2014-09-10 105 views
-3

我使用的Java版本1.7 WHERE子句字符串我有一個字符串:解析Java中

String customerList="'C1','C2','C3','C4','C5'"; 

我想每一個客戶解析成單獨的字符串,如

字符串C1,C2, C3,C4和C5

我該怎麼做?

+0

String [] customers = customerList.splitString(「,」); – StackFlowed 2014-09-10 20:08:40

+0

'split()'和'replace()' – 2014-09-10 20:08:45

回答

3

例如:

String customerList="'C1','C2','C3','C4','C5'"; 
for(String s : customerList.split(",")) { 
    System.out.println(s.replaceAll("'", "")); 
} 
1
String customerList="'C1','C2','C3','C4','C5'";  

String[] a = customerList.replace("'", "").split(","); 

現在a持有Strings"C1", "C2"等...

測試用:

for(String x : a) 
    System.out.print(x + " "); 

將打印C1 C2 C3 C4 C5