Parsing a string in java

Hi,
I have a string of the form <user>id</user>text<user>id2</user>text1<user>id3</user>
I want to convert this String to <user>name</user>text<user>name2</user>text1<user>name3</user>
Basically each userId has a corresponding name which i need to fetch from DB and replace this id with the name.
How do i do it effeciently in java.

Thanks
Rohit BajajAsked:
Who is Participating?
 
Pawan KumarConnect With a Mentor Database ExpertCommented:
Please try with REGEX.
0
 
ste5anConnect With a Mentor Senior DeveloperCommented:
What about using XML and XSLT?
0
 
CEHJCommented:
Your problem has nothing to do with "parsing a string". It's to do with filling a template. You need to replace placeholders (id,id2,id3 etc) with the actual values. Commonly, this is often done with templating software such as Velocity
The same could go for
https://www.experts-exchange.com/questions/29071171/Mentions-on-a-page-how-to-handle.html
0
 
Rohit BajajAuthor Commented:
There is one reason why templating probably could not apply here... correct me if i am wrong...
<user>id</user>text<user>id2</user>text1<user>id3</user>
In the above string i need to extract the id and then search for a corresponding name in DB and replace it there
So i need to fetch the id , id2 etc. values which will require parsing it..
0
 
CEHJCommented:
Oh sorry - i thought it was the other way around ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.