mrs.tat
mrs.tat

Reputation: 697

substring till first occurrence of comma in a string

I have a string like this:

String s = "first link, second link, third link, fourth link"

I want to divide each in a separate string and put it in a list of strings like this:

List<String> s = ["first link","second link","third link","fourth link"]

how to do this?

Upvotes: 1

Views: 1145

Answers (1)

Ludo
Ludo

Reputation: 157

Check out the Split method to create an array from a string

Using your example:

String s = "first link, second link, third link, fourth link"    
s.split(", "); // will return ['first link', 'second link', 'third link', 'fourth link'];

Upvotes: 2

Related Questions