Extraction of attribute values from pattern matches

P

Peekachu

Hi,

My program has to deal with a lot of text of the pattern:

"Name=userLocale", "Value=English", ENDITEM

I need to do two things:
1> Check if the text matches a certain pattern.
2> If there is a pattern match, extract the attribute value parts
('userLocale' and 'English', in the text above) of the text into
Strings or a String array.

The first part is easy to do using the Pattern and Matcher classes. I
am struggling with the second part. It is easy to do it using the
String class methods such as 'split' and 'substring' but I was looking
for a more elegant way to do this, since I need to do this operation in
several places throughout my program.

Thanks,
Peekachu
 
O

Oliver Wong

Peekachu said:
Hi,

My program has to deal with a lot of text of the pattern:

"Name=userLocale", "Value=English", ENDITEM

I need to do two things:
1> Check if the text matches a certain pattern.
2> If there is a pattern match, extract the attribute value parts
('userLocale' and 'English', in the text above) of the text into
Strings or a String array.

The first part is easy to do using the Pattern and Matcher classes. I
am struggling with the second part. It is easy to do it using the
String class methods such as 'split' and 'substring' but I was looking
for a more elegant way to do this, since I need to do this operation in
several places throughout my program.

Write a parser with transforms your strings into model objects
representing the information. For inspiration, see XML parsers and DOM.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top