473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Best way to extract one or more substring values?

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
1 8608
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason | last post by:
I need to split a string in two if there are lowercase characters at the end of it. For example: 'AAPLpr' becomes 'AAPL' and 'pr' 'Ta' becomes 'T' and 'a' 'MSFT' ...
3
by: JIM.H. | last post by:
Hi, I have this string 111_XYZ11_2345, 22_zz22_33, .., How can I extract only last numbers like 2345 and 33. Thanks, Jim.
4
by: rdraider | last post by:
Is there a function that will extract part of a string when the data you want does not occur in a specific position? Field "REF" is varchar(80) and contains an email subject line and the email...
9
by: Sharon | last post by:
hi, I want to extract a string from a file, if the file is like this: 1 This is the string 2 3 4 how could I extract the string, starting from the 10th position (i.e. "T") and...
3
by: jarod1701 | last post by:
Hi, I'm currently trying to create a regular expression that can extract certain elements from a url. The url will be of the following form: http://user:pass@www.sitename.com I want a...
1
by: Nick | last post by:
Hi, I'm trying to extract element of a directory path stored in the db with substring "/help/support/index/time.jsp" and i want to extract the 1st, 2nd and 3rd parts 1st = help, 2nd =...
1
by: Patrick Sullivan | last post by:
I am trying to extract two parts of a number from an array element. Numbers are in the format of 1.10, 2.50, 11.10, etc. Floor and ceiling won't work right because close to 1.00, I get a zero, and...
7
by: Sling | last post by:
I code in Rexx on the mainframe which has 2 built-in functions: word(s,i) & words(s). word(s,i) returns the ith word in the s(tring), and words(s) returns the number of words within the s(tring)....
8
by: Fabian Braennstroem | last post by:
Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.