我有一个字符串“Magic Word”。我需要修剪字符串才能提取“魔术”。 我正在做下面的代码。在java中修剪一个字符串以获取第一个字
String sentence = "Magic Word";
String[] words = sentence.split(" ");
for (String word : words)
{
System.out.println(word);
}
我只需要第一个单词。 是否有任何其他方法修剪字符串以获取第一个字只有在space
发生?
字符串firstWord = sentence.split(”“)[0]; ?? – Syam 2012-07-23 06:39:38
重复的https://stackoverflow.com/questions/5067942/what-is-the-best-way-to-extract-the-first-word-from-a-string-in-java – AsfK 2017-12-07 15:44:22