Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split String before first comma?

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:

  1. String before first comma and

  2. String after first comma

My overriding method is :

@Override
protected void onPostExecute(String addressText) {

    placeTitle.setText(addressText);
}

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

like image 873
Santosh Bhandary Avatar asked Jun 02 '15 05:06

Santosh Bhandary


People also ask

How to split a string separated by commas into several columns?

Combining TRIM, MID, SUBSTITUTE, REPT, and LEN functions together helps us to split a string separated by commas into several columns. Just follow the steps below to do this. First, enter 1, 2, and 3 instead of columns titles ID No., LastName, and Dept. Now, write down the following formula in an empty cell C5.

How do you break up a comma in a string?

Use Split to break up comma delimited lists, dates that use a slash between date parts, and in other situations where a well defined delimiter is used. A separator string is used to break the text string apart.

How do you break up a comma delimited list in Python?

Use Split to break up comma delimited lists, dates that use a slash between date parts, and in other situations where a well defined delimiter is used. A separator string is used to break the text string apart. The separator can be zero, one, or more characters that are matched as a whole in the text string.

How to split a string with multiple comma chunks in Python?

In this example, we will take a string with chunks separated by comma ,, split the string and store the items in a list. If you use String.split () on String with more than one comma coming adjacent to each other, you would get empty chunks.


1 Answers

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());
like image 83
Razib Avatar answered Oct 02 '22 14:10

Razib