如何在第一个逗号之前拆分String? [英] How to split String before first comma?
本文介绍了如何在第一个逗号之前拆分String?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个覆盖String的方法,该方法以以下格式返回String:
I have an overriding method with String which returns String in format of:
"abc,cde,def,fgh"
我想将字符串内容分为两部分:
I want to split the string content into two parts:
-
第一个逗号前的字符串和
String before first comma and
第一个逗号后的字符串
我的替代方法是:
@Override
protected void onPostExecute(String addressText) {
placeTitle.setText(addressText);
}
现在如何将字符串分成两部分,以便可以使用他们将文本设置为两个不同的 TextView
?
Now how do I split the string into two parts, so that I can use them to set the text in two different TextView
?
推荐答案
使用以下代码段
String str ="abc,cde,def,fgh";
String kept = str.substring( 0, str.indexOf(","));
String remainder = str.substring(str.indexOf(",")+1, str.length());
这篇关于如何在第一个逗号之前拆分String?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文