Santosh Bhandary Santosh Bhandary - 1 year ago 124
Java Question

How to split String before first comma?

I have an overriding method with String which returns String in format of:

I want to split the string Content into two parts:

1) String before first comma and

2) String after first comma

My overriding method is :

protected void onPostExecute(String addressText) {


Now how do I split the string into two parts, so that I can use them to set the text in two different

Answer Source

You may use the following code snippet -

String str ="abc,cde,def,fgh";
String kept = str.substring( 0, str.indexOf(","));
String remainder = str.substring(str.indexOf(",")+1, str.length);             
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download