我有字符串
Intel Corporate|Lot 8, Jalan Hi-tech 2/3|Kulim Hi-tech Park|Kulim Kedah 09000|Malaysia
Samsung Electronics||#94-1, Imsoo-dong|Gumi Gyeongbuk 730-350|Korea, Republic Of
如何打印供应商名称,如英特尔公司,三星电子?
答案 0 :(得分:3)
看看String#split
...
我想你会找到类似的东西......
String value = "Intel Corporate|Lot 8, Jalan Hi-tech 2/3|Kulim Hi-tech Park|Kulim Kedah 09000|Malaysia";
System.out.println(value.split("\\|")[0]);
value = "Samsung Electronics||#94-1, Imsoo-dong|Gumi Gyeongbuk 730-350|Korea, Republic Of";
System.out.println(value.split("\\|")[0]);
应该足够......
答案 1 :(得分:3)
您可以使用拆分,如下所示:
String[] tokens = phrase.split("\\|");
然后像这样打印出来:
for (int i = 0; i < tokens.length; i++)
System.out.println(tokens[i]);