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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove commas from string 1

Status
Not open for further replies.

pugs421

Technical User
Nov 25, 2002
114
US
Is there a "find and relace" function that I can use in actionscript to remove the commas from a string that the user enters into a text field?

I need to remove all commas from a text string.

Thanks
 
Try String.split();

Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
That didn't seem to work. I wrote a function to remove the needle from the haystack. Code and example below. I'm sure that there is an easier way to do this simple task, but I need to get this project done.

Thanks.
-----------

function removeChar(haystack,needle){
var needleLocation = haystack.indexOf(needle);
while (needleLocation>= 0) {
haystackPrefix = haystack.substr( 0 , needleLocation);
haystackSuffix = haystack.substr( needleLocation + 1 , length(haystack));
haystack = haystackPrefix + haystackSuffix;
needleLocation = haystack.indexOf(needle);
}
return haystack;
}

----

removeChar(_root.inputTextField,",");

 
Try this - split string into array, then join array back together:

Code:
function removeChar(haystack, needle) {
	arr = haystack.split(',');
	return arr.join(' ');
}
strTest = removeChar(_root.inputTextField, ",");
trace(strTest);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top