【发布时间】:2015-04-03 08:52:21
【问题描述】:
我得到以下字符串:
String line = "#food was testy. #drink lots of. #night was fab. #three #four";
我想从中获取#food#drink#night#three和#four。
我试过这段代码:
String[] words = line.split("#");
for (String word: words) {
System.out.println(word);
}
但它给出了food was testy、drink lots of、nigth was fab、three 和 four。
【问题讨论】:
-
你为什么要这样尝试。你知道字符是“#”。所以 System.out.println("#"+word);
标签: java string extraction