/*
* public int length()
* public char charAt(int index):返回在指定index位置的字符。index从0开始
* public boolean equals(Object anObject):比较两个字符串是否相等。相等返回true.否则返回-1
* public int compareTo(String anotherString)
* public int indexOf(String s):返回s字符串在当前字符串中首次出现的位置。若没有,返回-1
* public int indexOf(String s,int startpoint):返回s字符串从当前字符串startpont位置开始,首次
* 出现的位置
* public int lastIndexOf(String s):返回s字符串最后一次在当前字符串中出现的位置。若无返回-1
* public int lastIndexOf(String s,int startpoint)
* public boolean startsWith(String prefix):判断当前字符串是否以perfix开始
* public boolean endWith(String suffix):判断当前字符串是否以suffix结束
* public boolean regionMathces(int firstStatr,String other,int otherStart,int length)
* 判断当前字符串从firstSrart开始的字串与另一个字符串other从otherStart开始,length长度的字串是否equals
* */
/*
- public String substring(int startpoint)
- public String substring(int start,int end):返回从start开始到end结束的一个左闭右开字符串
- public String replace(char oldChar,char newChar);
- public String replaceAll(String old,String new);
- public String trim()去除当前字符串中首尾出现的空格
- public String concat(String str)连接当前字符串与str
- public String[] split(String regex):按照regex将当前字符串拆分成多个字符串,整体返回为String[]
- */
package day18;
import org.junit.Test;
/**
* @author 许泽鑫
* @data 2019/10/9 - 14:59
*/
public class TestString {
/*
* public int length()
* public char charAt(int index):返回在指定index位置的字符。index从0开始
* public boolean equals(Object anObject):比较两个字符串是否相等。相等返回true.否则返回-1
* public int compareTo(String anotherString)
* public int indexOf(String s):返回s字符串在当前字符串中首次出现的位置。若没有,返回-1
* public int indexOf(String s,int startpoint):返回s字符串从当前字符串startpont位置开始,首次
* 出现的位置
* public int lastIndexOf(String s):返回s字符串最后一次在当前字符串中出现的位置。若无返回-1
* public int lastIndexOf(String s,int startpoint)
* public boolean startsWith(String prefix):判断当前字符串是否以perfix开始
* public boolean endWith(String suffix):判断当前字符串是否以suffix结束
* public boolean regionMathces(int firstStatr,String other,int otherStart,int length)
* 判断当前字符串从firstSrart开始的字串与另一个字符串other从otherStart开始,length长度的字串是否equals
* */
@Test
public void test(){
String str1 = "abcdefghijkabc";
String str2 = "abc";
System.out.println(str2.length());
System.out.println(str1.charAt(10));
System.out.println(str1.equals(str2));
System.out.println(str2.equals("abc"));
System.out.println(str1.compareTo(str2));
System.out.println(str1.indexOf(str2));
System.out.println(str1.lastIndexOf(str2));
System.out.println(str1.indexOf(str2,1));
System.out.println(str1.lastIndexOf(str2,4));
System.out.println(str1.regionMatches(11,str2,0,str2.length()));
}
@Test
/*
* public String substring(int startpoint)
* public String substring(int start,int end):返回从start开始到end结束的一个左闭右开字符串
* public String replace(char oldChar,char newChar);
* public String replaceAll(String old,String new);
* public String trim()去除当前字符串中首尾出现的空格
* public String concat(String str)连接当前字符串与str
* public String[] split(String regex):按照regex将当前字符串拆分成多个字符串,整体返回为String[]
* */
public void test1(){
String str1 = new String("北京卢本伟爱马飞飞");
String str2 = new String("伤害卢本伟爱柚柚妹");
String str3 = str1.substring(2);
System.out.println(str3);
System.out.println(str1.substring(2,5));
System.out.println(str1.replace("马飞飞","柚柚妹"));
System.out.println(str1);
String str5 = new String(" abc d ");
String str6 = str5.trim();
System.out.println(str5);
String str7 = str1.concat(str2);
System.out.println(str7);
String str8 = "abc*d-e7f-ke";
String[] strs = str8.split("-");
for (int i = 0; i < strs.length; i++) {
System.out.println(strs[i]);
}
}
}