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

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

 

 

 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *