2012-01-03 4 views
2

문자열 빌더에서 문자 세트를 분할하는 방법이 있습니까? 예를 들어 "One Two Three Four"가있는 경우 foreach 루프를 사용하여 목록에 넣을 수있는 개별 단어를 가져 오는 방법이 있습니다.stringbuilder에서 문자 세트를 자르는 방법은 무엇입니까?

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

답변

2

난 당신과 같이 첫 번째 문자열로 변환해야 배열에 모두 StringBuilder를 분할하는 직접적인 방법이 없다는 생각에 대한

1

암호. 희망이 당신의 업무에 도움이 되길 바랍니다.

//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); 
     } 
+0

그래, 나는 이미 답을 알고 있지만 어쨌든 고마워. – user1099719

0

아래 언급 사용하여보십시오 : 자바

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