Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Parse String In Java With * [duplicate]

Tags:

java

I have a string like this.

PER*IP**TE**1234567890*EM*[email protected]

How can I parse the string into multiple lines like this in Java?

PER
IP
TE
//Empty String
EM
1234567890
[email protected]
like image 435
JIANG Avatar asked Sep 20 '26 22:09

JIANG


1 Answers

You could use a regex replacement:

String input = "PER*IP**TE*1234567890*EM*[email protected]";
String output = input.replaceAll("\\*", "\n");
System.out.println(output);

This prints:

PER
IP

TE
1234567890
EM
[email protected]
like image 89
Tim Biegeleisen Avatar answered Sep 23 '26 12:09

Tim Biegeleisen