2012年6月2日 星期六

Intermediate Java(2) - Some More String Methods


public class apples{
public static void main(String[] args){
String s = "iamsohappytoday";
String a = "I am ";
String b = "happy";
String c = " HaHA ";
System.out.println(s.indexOf('a')); → string s哪個位置有a
System.out.println(s.indexOf('t',6)); 由第6個位置開始,string s哪個位置有t,
System.out.println(s.indexOf("tod",6));由第6個位置開始,string s哪個位置有tod,
System.out.println(a.concat(b)); 等於 string a + string b
System.out.println(a.replace("I am","you are")); → you are取代I am
System.out.println(b.toUpperCase()); 全部大寫
System.out.println(c.trim()); 忽略所有的space
}
}

這是運行時的結果:

1
10
10
I am happy
you are
HAPPY
HaHA

沒有留言:

張貼留言