Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java String Methods - Codehs

Similar presentations


Presentation on theme: "Java String Methods - Codehs"— Presentation transcript:

1 Java String Methods - Codehs

2 String Construction The numbers refer to the place of the Character within the string. Note it starts with 0, not 1.

3 .substring word.substring(0,1);
Where “word” is the string variable (eg. “hello”) and (0, 1) is the first character place. word.substring(length – 1); Where (length – 1) is the last character in the string.

4 .length word.length(); Where “word” is the string variable, this will output an integer. Eg. string word = “hello”; int x = word.length(); X = 5

5 .toUpperCase word.toUpperCase(); Where “word” is the string variable. Eg. string word = “hello”; string uppercase = word.toUpperCase(); uppercase = “HELLO”;

6 .charAt word.charAt(i); Where “word” is the string variable. Often used in a for loop. Eg. String word = “hello”; for(i = 0; i < length; i++){ char x = word.CharAt(i); return x; }

7 .isDigit Character.isDigit(x); Where x is the character variable. Often used in if statements. Eg. if(Character.isDigit(x)){ x = true; }else{ x = false; }

8 Character.toUpperCase (and Character.toLowerCase)
Character.toUpperCase(x); Where x is the character variable to be converted to upper or lower case. Eg. char x = a; Char y = Character.toUpperCase(x); y = A;

9 Character.toString Character.toString(x); Where x is the character variable. This is used in a for loop to add characters to a string. Eg. string longword = “”; char word = Character.toString(x); longword += word;

10 Character.isLetterOrDigit
Character.isLetterOrDigit(x); Where x is the character variable. Usually used in an if statement or boolean. Eg. char x = ‘5’; Boolean digit = Character.isLetterOrDigit(x); digit = true;


Download ppt "Java String Methods - Codehs"

Similar presentations


Ads by Google