Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string problem

Status
Not open for further replies.

Bignewbie

Programmer
Feb 22, 2001
351
PH
hi guys!

got a bit of a problem here, how can i take out this string :

"chocolate;"

in a dynamic textbox that has:

"milk; chocolate; and coffee;"


this has to be done at runtime, when i press a button.

wish u can help me with this.


thanks and hoping for ur answers....


biggie


 
hey guys,

dont sweat it anymore. i kinda solve it with a little persistence. thanks anyway for those who wish to help.

thanks

biggie
 
How about this?

Frame 1



// function for searching through string

function parseString (testString, searchItem) {
for (i=0; i<testString.length; i++) {
// check for first letter
found = &quot;&quot;;
if (searchItem.charAt(0) == testString.charAt(i)) {
// if first letter is found search for substring
for (j=0; j<searchItem.length; j++) {
if (searchItem.charAt(j) == testString.charAt(i+j)) {
found += testString.charAt(i+j);
// if complete match is found return result
if (found == searchItem) {
return found;
}
}
}
}
}
// if no match is found
found = &quot;Search item not found.&quot;;
return found;
}


Frame 2

//
//initialise variables for your example
//

text = &quot;milk;chocolate; and coffee;&quot;;
testString = new String(text);
find = &quot;chocolate;&quot;;
searchItem = new String(find);
//
//go find your example
//

result=parseString(testString,searchItem);
trace(result);
stop();
 
Aha, beat me to it! No sweat, it was an interesting problem anyway :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top