[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

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,29 again the same pattern for the other strings like first name, ln name, city , state
  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('&searchFName=TEXTILES&searchMName=&searchLName=WINKY&searchCity=NEW+YORK&searchState=NY&searchApproxAge=29&searchStateJurisdiction=NY&searchGender=&searchZip=&vid=cfc&searchAgentNotes=PREVIEW-CFC', 'ENH1078249456', '**/**/00', '51540c04140a03510'); displayL2Result('0', 'ENH1078249456', 'off');

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('&searchFName=TIMOTHY&searchMName=J&searchLName=WINKY&searchCity=NEW+LENOX&searchState=IL&searchApproxAge=29&searchStateJurisdiction=IL&searchGender=&searchZip=&vid=cfc&searchAgentNotes=PREVIEW-CFC', 'ENH1078249457', '**/**/00', '65050a021d5c4d4a8'); displayL2Result('1', 'ENH1078249457', 'off');
2
Can't Find Who You're Looking for?
Let an Expert Run Your Search...
"
0
cutie_smily
Asked:
cutie_smily
  • 5
  • 4
1 Solution
 
aozarovCommented:
you can use the String#indexOf(java.lang.String) method.
0
 
cutie_smilyAuthor Commented:
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.

0
 
aozarovCommented:
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 "=")
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
cutie_smilyAuthor Commented:
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",____);
0
 
aozarovCommented:
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);
}
0
 
cutie_smilyAuthor Commented:


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
0
 
aozarovCommented:

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 + 1, index2);
index1 = index2;
}
else
{
// the match should be str.substring(indexOfEqual);
index1 = -1;
}
}
0
 
cutie_smilyAuthor Commented:
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);

0
 
aozarovCommented:
you can define a set of what you are looking for:
Set acceptOnly = new HashSet();
accepOnly.add("FName");
accepOnly.add("MName");
accepOnly.add("LName");
...
then:

int index1 = str.indexOf("&search", index1);

while (index1 != -1)
{
int indexOfEqual = str.indexOf("=", index1 + 1);
String searchType = str.substring(index1 + 7, indexOfEqual);
int index2 = str.indexOf("&search", indexOfEqual + 1);
String match = null;
if (index2 > 0)
{
match = str.substring(indexOfEqual + 1, index2);
index1 = index2;
}
else
{
match = str.substring(indexOfEqual);
index1 = -1;
}

if (acceptOnly.contains(searchType))
   System.out.println(searchType + ": " + match);
}

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now