2013年10月20日 星期日

Java 字串切割(分割)「String split() Method」

Java 字串切割(分割)「String split() Method」



拷貝來源:http://www.tutorialspoint.com/java/java_string_split.htm


程式碼:









import java.io.*;

public class Test{
public static void main(String args[]){
String Str = new String("Welcome-to-Tutorialspoint.com");

System.out.println("Return Value :" );
for (String retval: Str.split("-", 2)){
System.out.println(retval);
}
System.out.println("");
System.out.println("Return Value :" );
for (String retval: Str.split("-", 3)){
System.out.println(retval);
}
System.out.println("");
System.out.println("Return Value :" );
for (String retval: Str.split("-", 0)){
System.out.println(retval);
}
System.out.println("");
System.out.println("Return Value :" );
for (String retval: Str.split("-")){
System.out.println(retval);
}
}
}


 


運算結果:









Return Value :
Welcome
to-Tutorialspoint.com


Return Value :
Welcome
to
Tutorialspoint.com


Return Value:
Welcome
to
Tutorialspoint.com


Return Value :
Welcome
to
Tutorialspoint.com



 


 


 


沒有留言:

張貼留言