2012-01-03 30 views

回答

2

我覺得這是對的StringBuilder拆分到一個數組沒有直接的方法,你需要轉換爲字符串第一,像這樣:

StringBuilder sb = new StringBuilder(); 
    sb.append("One Two Three Four"); 
    String[] myArray = sb.toString().split(" "); 
1

爲Java

StringBuilder sb = new StringBuilder("One Two Three Four"); 
String[] words = sb.toString().split("[\\s]+"); 
+0

是的我現在已經知道了答案,不過謝謝你 – user1099719 2012-01-03 11:27:17

0

,請嘗試使用下面提到碼。希望它可以幫助你完成你的任務:

//Create Stringbuilder 

     StringBuilder strb = new StringBuilder(); 
     strb.Append("One Two Three Four"); 

     // Convert Stringbuilder to string 
     string a = strb.ToString(); 

     // Split the string based on seprator. Here seprator is space " " 
     string[] str = a.Split(); 

     List<string> al1 = new List<string>();   

     // Add the word of splited string to a string List 
     foreach (string str1 in str) 
     { 
      al1.Add(str1); 
     } 
相關問題