Android拆分字符串

我有一个叫做的字符串CurrentString,它的形式像这样 "Fruit: they taste good"
我想CurrentString使用:分隔符。
这样一来,单词"Fruit"将被拆分成自己的字符串,"they taste good"并将成为另一个字符串。
然后我只想使用SetText()2种不同的TextViews字符串来显示该字符串。

解决此问题的最佳方法是什么?




慕码人2483693
浏览 308回答 3
3回答

慕尼黑5688855

split方法可以使用,但是使用正则表达式。在此示例中(从克里斯蒂安那里窃取):String[] separated = CurrentString.split("\\:");separated[0]; // this will contain "Fruit"separated[1]; // this will contain " they taste good"

慕娘9325324

Android用逗号分割字符串String data = "1,Diego Maradona,Footballer,Argentina";String[] items = data.split(",");for (String item : items){    System.out.println("item = " + item);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java