vimwiki

String methods

full list

.length()

String str1 = "hello";
str1.length()

.concat()

Return a new string

String str1 = "hello";
newStr = str1.concat(" world!")

.equals()

String behing an object, the == operator does not work.

String str1 = "foo";
String str2 = "bar";
boolean test = str1.equals(str2);

there is also .equlsIgnoreCase()

.indexOf()

String letters = "abcde";
letters.indexOf("c"); // 2
letters.indexOf("cde"); // 2

.charAt()

String str1 = "foo";
str1.charAt(2);

.substring()

String str1 = "abcde"
str1.substring(2); // index 2 to the end
str1.substring(0, 3); // index 0 to 2

.toUpperCase() .toLowerCase()

String str1 = "aBcD"
str2 = str1.toLowerCase()
str3 = str1.toUpperCase()