• Post Reply Bookmark Topic Watch Topic
  • New Topic

Word matching from a string and retrieving the value  RSS feed

 
Ullas padavan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

I need some advise on how to extract a specfic string value from the complex string?

my input string looks like

input str : <!-- template name: form.autopost.template.html --> <html> <head> <title>Submit Form</title> </head> <body onload="javascript:document.forms[0].submit()"> <noscript> <p> <strong>Note:</strong> Since your browser does not support JavaScript, you must press the Resume button once to proceed. </p> </noscript> <form method="post" action="https://abc.com"> <input type="hidden" name="State" value="https://abc.com"/> <input type="hidden" name="Response" value="jA6YXNzZXJ0aW9uIj5SQkNTU08yLjA8L3NhbWw6SXNzdWVyPjxkczpTaWduYXR1cmUge" <noscript><input type="submit" value="Resume"/></noscript> </form> </body></html>

From this string I want to match the word "Response" in this String and then retrieve the value of the "value=" str correspoding to that.

Thanks for advance.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean you want an HTML parser?
You can use the indexOf and substring methods of the String class, but you have to be absolutely sure that Response cannot occur anywhere earlier in the text.
Or better search for “Response value="”
 
Ullas padavan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it should a java string parser. There will be only one "Response" word in the entire string but there are different "value=" in the entire string that is confusing me a lot. What is the best way to search for the word "Response" and extract the specific value of that name? Could you please provide me a code snippet?

Thanks
 
Utha Ramadhan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you should use method substring and indexOf in java.lang.String Class..

for example :
first, you find the index of "Response" word from your value using indexOf(String value),
then you find the index of first "value" word that occur after indexOf "Response" using(String value, int begin),
etc..

and finally you get the value..

(and actually i think you can use Regex to get cleaner code, but of course need some extra effort to create the pattern )
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!