For the time being, it is summarized as a memorandum. It may not be practical. I will write from Java for the time being. Please point out if you write something strange.
Sample1.java
/**Combine character literals and constants**/
String final CONSTSTR = "A";
String strA = "A" + "B" + CONSTSTR; //Literals and constants+Good to combine with
System.out.println(strA); // ABA
/**Other joins**/
String strB = "B";
String strC = "C";
StringBuilder buff = new StringBuilder();
buff.append(strA);
buff.append(strB);
buff.append(strC);
This article is detailed https://qiita.com/yoshi389111/items/67354ba33f9271ef2c68
Sample2.java
/**Convert from string to number normally**/
String strA = "1";
int numA = Integer.parseInt(strA);
/**Considering exception handling, 0 is returned at the time of exception for the time being**/
String hoge = "hoge";
try {
int numB = Integer.parseInt(hoge);
} catch (NumberFormatException e) {
return 0;
}
Sample3.java
/**Cut out by specifying the start point and end point to cut out**/
String strA = "12345";
strA.substring(0,3); // 123
strA.substring(1,3); // 23
/**Cut out by specifying only the starting point to cut out**/
strA.substring(2); // 345
Sample4.java
/**Cut out only one character with Char type**/
String strA = "12345";
Char charA = strA.charAt(3); // 4
Sample5.java
/**White space before and after(Half-width only)Delete**/
String strA = " ABC ";
strA.trim(); // ABC
Sample6.java
String strA = "ABCABCABC";
/**Replace all A with X**/
strA.replace('A', 'X'); // XBCXBCXBC
/**Replace only the very first A with X**/
strA.replaceFirst('A', 'X'); // XBCABCABC
Sample7.java
String strA = "ABC";
String strB = null;
/**Determine if it is an exact match**/
"ABC".equals(strA); // true
"CBA".equals(strA); // false
/**If the character string to be judged is null, it is judged as false.**/
"ABC".equals(strB); // false
Sample8.java
String strA = "ABC";
String strB = "xyz";
/**Ignore case and determine if they match**/
"abc".equalsIgnoreCase(strA); // true
"XYZ".equalsIgnoreCase(strB); // true
Sample9.java
String strA = "ABCDE";
/**Determine if it is a prefix match or a suffix match**/
strA.startsWith("AB"); // true
strA.endWith("DE"); // true
Sample10.java
String strA = "";
/**Determine if the string is empty**/
strA.isEmpty(); // true
Sample11.java
String strA = "ABCDEFGHIJ";
/**Determine if a specific character string is included**/
strA.contains("DE"); // true
Recommended Posts