单个字符串的输出是
iPad 触控笔和圆珠笔
通常在 24 小时内发货
$9.99
我想将上述字符串的每一行保存到单独的字符串中,例如:
String one = "iPad Stylus & Ballpoint Pen";
String two = "Usually ships in 24 hrs";
String three = "$9.99";
应该使用什么方法?
String inputString = " iPad Stylus & Ballpoint Pen
Usually ships in 24 hrs
$9.99";
String lines[] = inputString.split("\\r?\\n");
使用番石榴:
Splitter splitter = Splitter.on('\n').trimResults().omitEmptyStrings();
Iterable<String> items = splitter.split(text);