//定義字符串求返回值,并判斷字符串是否正確
public class String02 {
public static void main(String[] args) {
//定義一個字符串
String name="www.baidu.com";
//字符的索引是從0到字符串名.length()-1
//多個相同字符,默認返回第一個字符的值
int index=name.indexOf('w');
int index2=name.indexOf('.');
//q不屬於字符串中的字符,返回-1
int index3=name.indexOf('q');
System.out.println(name.length());
System.out.println(index);
System.out.println(name.indexOf("w"));
System.out.println(index2);
System.out.println(name.indexOf("."));
System.out.println(index3);
System.out.println(name.indexOf("q"));
System.out.println(name.indexOf("b"));
System.out.println(name.indexOf("u"));
//baidu中的b的返回值為4,u的返回值為8
//因為在substring(0,字符串名.leng())的範圍內,比字符的索引多1
//所以,u對應的int endIndex是8+1
//[int beginIndex,int endIndex),[對應當前值,)對應當前值+1
String prefix=name.substring(4,9);
System.out.println(prefix.equals("baidu"));
System.out.println(name.indexOf('c'));
System.out.println(name.indexOf('m'));
String prefix2=name.substring(10, 13);
System.out.println(prefix2.equals("com"));
if(index!=-1&&index<index2&&prefix2.equals("com")){
System.out.println("網址正確!");
}else{
System.out.println("網址錯誤!");
}
String prefix3=name.substring(0);
System.out.println(prefix3.equals("www.baidu.com"));
}
}