Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

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
SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of Rohit Bajaj

ASKER

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..
Oh sorry - i thought it was the other way around ;)