Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting a period-delimited string into multiple strings

Tags:

java

android

I have a string

String x = "Hello.August 27th.Links.page 1";

I am wondering if I can split this string into 4 other strings based on where the period is. For example, the four other strings would be,

String a = "Hello";
String b = "August 27th";
String c = "Links";
String d = "page 1";

As you can see I basically want to extract certain parts of the string out into a new string, the place where it is extracted is based on where the period is which ends the first string and then shows where the 2nd and, etc. strings end.

Thanks in advance!

In android btw

like image 445
Drake Avatar asked Nov 29 '22 16:11

Drake


2 Answers

Use String#split (note that it receives a regex as a parameter)

String x = "Hello.August 27th.Links.page 1";
String[] splitted = x.split("\\.");
like image 101
MByD Avatar answered Dec 10 '22 01:12

MByD


Yes of course just use:

  String[] stringParts =  myString.split("\\.")
like image 25
Oscar Gomez Avatar answered Dec 10 '22 02:12

Oscar Gomez