0

我有字符串

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

如何打印供应商名称,例如 Intel Corporate、Samsung Electronics?

4

2 回答 2

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]);

应该够...

于 2013-01-25T00:24:31.843 回答
3

您可以使用拆分,如下所示:

String[] tokens = phrase.split("\\|");

然后像这样打印它们:

for (int i = 0; i < tokens.length; i++)
    System.out.println(tokens[i]);
于 2013-01-25T00:25:06.540 回答