By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,558 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,558 IT Pros & Developers. It's quick & easy.

Best way to extract one or more substring values?

P: n/a
I am looking to extract form element values from html, more generally
I have a substring that identifies the beginning of a value and a
string that identifies the end of value and I need to extract the
substring.

My ugly code looks like this:

public static String getValue(String data, String begin, String end) {

int delimPos = data.indexOf(delim, data.indexOf(begin) +
begin.length());
int startPos = data.indexOf(begin) + begin.length();
if (delimPos ===1)
delimPos = data.length();
return data.substring(startPos, delimPos);
}

Of course now I need more functionality. Say I have
<html>....<form ...><input name="val1" value="123"><input
name="val1" value="456">..</html>

I want to extract 123 and 456, is there a better way - perhaps using
StringTokenizer?

thanks

TIm
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ti*******@hotmail.com (Tim Smith) wrote in message news:<a7*************************@posting.google.c om>...
I am looking to extract form element values from html, more generally
I have a substring that identifies the beginning of a value and a
string that identifies the end of value and I need to extract the
substring.

My ugly code looks like this:

public static String getValue(String data, String begin, String end) {

int delimPos = data.indexOf(delim, data.indexOf(begin) +
begin.length());
int startPos = data.indexOf(begin) + begin.length();
if (delimPos ===1)
delimPos = data.length();
return data.substring(startPos, delimPos);
}

Of course now I need more functionality. Say I have
<html>....<form ...><input name="val1" value="123"><input
name="val1" value="456">..</html>

I want to extract 123 and 456, is there a better way - perhaps using
StringTokenizer?

thanks

TIm


Regular expression(java.util.regex) surely will serve you. There's a
good tutorial on java.sun.com.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.