cutie_smily
asked on
how to get the desired text from the given string.
I have a string called str which holds huge data. Without using regular expressions. what approach or how do u look for the strings that u want ..
Clip...............
str = "all unnecessary data in the begining and the strings that i wanna is lying in the below lines and they are
TEXTILES,WINKY,NEW+YORK,NY
Preliminary Search Results for:
"Twinky R Winky"
displayDisplayName('1', "http://www.ussearch.com/consumer/cwf?adID=10002101&action=browseproduct&searchtab=people&pid=3064&searchPerson=ENH1078249456&searchFName=TEXTILES&searchMName=&searchLName=WINKY&searchCity=NEW+YORK&searchState=NY&searchApproxAge=29&searchStateJurisdiction=NY&searchGender=&searchZip=&vid=cfc&searchAgentNotes=PREVIEW-CFC", 'TEXTILES','','WINKY', '0', 'ENH1078249456', 'off'); displayAgeCityState('-', 'NEW YORK', 'NY'); displayPremiumUrls('&searc
displayDisplayName('2', "http://www.ussearch.com/consumer/cwf?adID=10002101&action=browseproduct&searchtab=people&pid=3064&searchPerson=ENH1078249457&searchFName=TIMOTHY&searchMName=J&searchLName=WINKY&searchCity=NEW+LENOX&searchState=IL&searchApproxAge=29&searchStateJurisdiction=IL&searchGender=&searchZip=&vid=cfc&searchAgentNotes=PREVIEW-CFC", 'TIMOTHY','J','WINKY', '1', 'ENH1078249457', 'off'); displayAgeCityState('-', 'NEW LENOX', 'IL'); displayPremiumUrls('&searc
2
Can't Find Who You're Looking for?
Let an Expert Run Your Search...
"
you can use the String#indexOf(java.lang.S tring) method.
ASKER
I know that function i do want to use it because there are 100's of names. want i want do is whenever in the str we found
&searchFName= grab the text after searchFName=
&searchLName=
searchMName=
searchCity=
searchState=
grab the text whatever it is after these words... and put it in a vector or in array of strings???
pointer should read in a forward direction.
&searchFName= grab the text after searchFName=
&searchLName=
searchMName=
searchCity=
searchState=
grab the text whatever it is after these words... and put it in a vector or in array of strings???
pointer should read in a forward direction.
You can do that using regexp, but I see you don't want to.
you can still search for indexOf("&search", from_index);
where you keep your from_index equal to the previous find + 7.
You take the value between each indexes (which will be in the form of XXX=your string) and then take the substring after the index of "=")
you can still search for indexOf("&search", from_index);
where you keep your from_index equal to the previous find + 7.
You take the value between each indexes (which will be in the form of XXX=your string) and then take the substring after the index of "=")
ASKER
what should be the value for from index...can u make write it in clear ..how are u calculating it???
if(str.indexof(("&search" )!=-1)
{
str.indexOf("&search",____ );
if(str.indexof(("&search" )!=-1)
{
str.indexOf("&search",____
the value returned by indexOf is -1 if not found or the start index of the string if found.
int index1 = str.indexOf("&search");
if (index1 > 0)
{
int indexOfEqual = str.indexOf("=", index1 + 1);
int index2 = str.indexOf("&search", indexOfEqual + 1);
if (index2 > 0)
// the match should be str.substring(indexOfEqual + 1, index2);
else
// the match should be str.substring(indexOfEqual );
}
int index1 = str.indexOf("&search");
if (index1 > 0)
{
int indexOfEqual = str.indexOf("=", index1 + 1);
int index2 = str.indexOf("&search", indexOfEqual + 1);
if (index2 > 0)
// the match should be str.substring(indexOfEqual
else
// the match should be str.substring(indexOfEqual
}
ASKER
Its getting only the first string...for the remaing strings ...needs a loop
or something to get remaming strings...how is that done
values of index1 and index2 will change to what
int index1 = str.indexOf("&search", index1);
while (index1 != -1)
{
int indexOfEqual = str.indexOf("=", index1 + 1);
int index2 = str.indexOf("&search", indexOfEqual + 1);
if (index2 > 0)
{
// the match should be str.substring(indexOfEqual
index1 = index2;
}
else
{
// the match should be str.substring(indexOfEqual
index1 = -1;
}
}
ASKER
aozarov , I want to get Firstname (FNname and LNname and MiddleInitial...) but it is getting the data which i do not need ..
search should start from &searchFName
but it is starting from &searchtab
need to modification so that it goes to &searchFName then do the below line
int index1 = str.indexOf("&search", index1);
str= " displayDisplayName('2', "http://www.ussearch.com/consumer/cwf?adID=10002101&action=browseproduct&searchtab=people&pid=3064&searchPerson=ENH1078249457&searchFName=TIMOTHY&searchMName=J&searchLName=WINKY&searchCity=NEW+LENOX&searchState=IL&searchApproxAge=29&searchStateJurisdiction=IL&searchGender=&searchZip=&vid=cfc&searchAgentNotes=PREVIEW-CFC", 'TIMOTHY','J','WINKY', '1', 'ENH1078249457', 'off'); "
something like...
int index1 = str.indexOf(&searchFName", index1);
int index1 = str.indexOf("&search", index1);
search should start from &searchFName
but it is starting from &searchtab
need to modification so that it goes to &searchFName then do the below line
int index1 = str.indexOf("&search", index1);
str= " displayDisplayName('2', "http://www.ussearch.com/consumer/cwf?adID=10002101&action=browseproduct&searchtab=people&pid=3064&searchPerson=ENH1078249457&searchFName=TIMOTHY&searchMName=J&searchLName=WINKY&searchCity=NEW+LENOX&searchState=IL&searchApproxAge=29&searchStateJurisdiction=IL&searchGender=&searchZip=&vid=cfc&searchAgentNotes=PREVIEW-CFC", 'TIMOTHY','J','WINKY', '1', 'ENH1078249457', 'off'); "
something like...
int index1 = str.indexOf(&searchFName",
int index1 = str.indexOf("&search", index1);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.