1. public String abbreviate(Integer maxWidth)
如果當(dāng)前 String 長度超過指定的長度,則附加省略號; 否則了赌,返回原始的不帶省略號的 String涉兽。maxWidth 參數(shù)的最小值是4
String s = 'Hello Maximillian';
String s2 = s.abbreviate(8);
System.debug(LoggingLevel.INFO, '*** s2: ' + s2);
2. public String abbreviate(Integer maxWidth, Integer offset)
從指定的字符偏移量 offset 開始貌嫡,返回長度為指定的長度 maxWidth的縮寫版String侵状。如果在這些位置刪除了字符蔚龙,則返回的 String 在開頭和結(jié)尾都添加了省略號青柄。
String s = 'Hello Maximillian';
// Start at M
String s2 = s.abbreviate(9,6);
System.debug(LoggingLevel.INFO, '*** s2: ' + s2);
3. public String capitalize()
如果第一個字符是字母伐债,則將第一個字母轉(zhuǎn)化為大寫字母,其余不變致开。
String s = 'hello maximillian';
String s2 = s.capitalize();
System.debug(LoggingLevel.INFO, '*** s2: ' + s2);
4. public Integer charAt(Integer index)
返回指定索引處字符的值峰锁。
String s = 'abcd';
Integer i = s.charAt(1);
System.debug(LoggingLevel.INFO, '*** i: ' + i);
5. public Boolean contains(String substring)
當(dāng)且僅當(dāng)調(diào)用該方法的 String 包含子字符串中指定的字符序列時返回 true。
String s = 'abcd';
String s2 = 'ab';
System.debug(LoggingLevel.INFO, '*** s.contains(s2): ' + s.contains(s2));
6. public Boolean containsAny(String inputString)(String substring)
如果當(dāng)前 String 包含指定 String 中的任何字符双戳,則返回 true; 否則返回 false虹蒋。
String s = 'hello';
Boolean b1 = s.containsAny('hx');
Boolean b2 = s.containsAny('x');
System.debug(LoggingLevel.INFO, '*** b1: ' + b1);
System.debug(LoggingLevel.INFO, '*** b2: ' + b2);
7. public Boolean containsIgnoreCase(String substring)
如果當(dāng)前 String 包含指定的字符序列而不考慮大小寫,則返回 true; 否則返回 false飒货。
String s = 'hello';
String s2 = 'H';
Boolean b1 = s.containsIgnoreCase(s2);
System.debug(LoggingLevel.INFO, '*** b1: ' + b1);