string manipulations

Solutions on MaxInterview for string manipulations by the best coders in the world

showing results for - "string manipulations"
Dario
28 Jun 2017
1boolean eq = name.equals(anotherName);                // equality
2
3String fruit = "Apple";
4int position = fruit.indexOf("pp");                   // 1 (if not found, -1)
5
6int length = fruit.length()                           // 5 (lenght)
7
8String sub = fruit.substring(1, 4);                   // exp: (1. index get into, 4. index does not)
9
10String upper = fruit.toUpperCase();                   // APPLE
11
12boolean empty = fruit.isEmpty();                      // false, with empty string true
13boolean blank = fruit.isBlank();                      // false, only true with white space character
14
15boolean startsWith = fruit.startsWith("app");         // true
16boolean endWith = fruit.endsWith("le");               // true
17boolean containsDoubleP = fruit.contains("pp");       // true
18String part = fruit.substring(0, 2).toLowerCase();    // ap - can be join
Lyle
28 May 2018
1String manipulations:
2charAt(indexNumber): it returns the char at the given index
3length(): returns the total number of characters as int
4		length is ALWAYS one unit above the maximum index number
5		maxIndex: length()-1;
6concat(Value): Concatenation, concats the given value to the String and returns a new value
7toLowerCase(): converts to lowercase and returns a new String
8toUpperCase(): converts to uppercase and returns a new String
9trim(): removes the unused spaces , and returns new String
10substring(beginning index, ending index): 
11creates substring of the string value from the beginning index till the ending                   
12substring(beginning index): 
13creates substring of the string value from the beginning index till the end of the stringreplace(old Value, new Value): new value will be replaced with ALL the given old value, and returns new string 
14replaceFirs(old Value, new Value): 
15new value will be replaced with  the very first given old value, and returns new string
16indexOf(Value): 
17returns the index number of the first occurred character as an int             
18indexOf(Value): returns the index number of first occurred character, as int
19lastIndexOf(Value): return the index number of last occurred character, as int
20isEmpty(): identifies if the string is empty
21                true ==> string is empty,
22                false ==> String is not empty
23equals(str): checks if two string' visible texts are equal or not
24                    cares about the case sensitivity
25                        A == a  ==> false
26 equalsIgnoreCase(str):  checks if two string' visible texts are equal or not
27                 does not care case sensitivity
28                    A == a ==> true
29 contains(str): checks if the str is contained in the string. returns boolean
30                    if str is conatined ==> true
31                    otherwise ==> false
32 startsWith(str): checks if the string starts with the given str. returns boolean
33                if starts with str ==> true
34                otherwise ==> false
35endsWith(str): checks if the string ended with the given str. returns boolean
36                 if ended with str ==> true
37                    otherwise ==> false