Functions
String - Using functions in combination
|
We can compose functions - this is where one function is applied to
another.
1. [ Java ] substring and equals
Show the name where the second and fourth letters
for countries with short names.
Burundi
- We use substring to extract the required characters
- We must use
.equals to compare the strings
== will NOT work.
test text
1. [ C# ] Substring and ==
Show the name where the second and fourth letters
for countries with short names.
Burundi
test text
2. [ Java ] substring with length
Extract the last two characters from the name of a country.
- The last character in String s has index
s.length()-1
- The character before this is at
s.length()-2
test text
2. [ C# ] Substring and Length
Extract the last two characters from the name of a country.
- The last character in String s has index
s.length()-1
- The character before this is at
s.length()-2
test text
3. [ Java ] toLowerCase and endsWith
Show the countries where the first and last letters are the same
(irrespective of case).
- The first letter is in name.substring(0,1), we turn this to
lower case.
test text
3. [ C# ] ToLower and EndsWith
Show the countries where the first and last letters are the same
(irrespective of case).
- The first letter is in name.substring(0,1), we turn this to
lower case.
test text
|