2011-12-03 53 views
0

我有一個EditText視圖,它允許用戶編輯地址字段。我想用一個逗號任何文本之前在新行被說得那麼例如以下: Some St., Some City, Some post code會被顯示爲:字符串內逗號的新行

Some St., 
Some City, 
Some post code 

有誰知道我能做到這一點?

回答

3

也許你可以執行String.replace(),\n

所以更換所有逗號,

String s = "Some St., Some City, Some post code" 
s = s.replace(",",",\n"); 

然後,您可能必須做一些事情來

或者刪除空格,刪除所有空白:

String s = "Some St., Some City, Some post code"; 
    String strings[] = s.split(","); 

     for(int i = 0; i < strings.length; i++){ 
     strings[i] = strings[i].trim(); 
     strings[i] += ",\n"; 
     } 
     s = ""; 

     for(int i = 0; i < strings.length; i++) 
     s += strings[i]; 
+0

我試試謝謝 – sam