Click to See Complete Forum and Search --> : manipulating a string


fark
10-08-2003, 10:30 AM
I have a string variable
strName="Test Test Test";
I need to replace all the spaces with a +
Is there a function for this or do I need to do it character by character
If I need to do it character by character how do I do that. I know how to do a for loop but how do I reference each character in the string?
Thanks

AdamGundry
10-08-2003, 10:36 AM
You can use regular expressions:

strName="Test Test Test";
strName = strName.replace(/ /g, '+');

See the documentation on String.replace() (http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/string.html#1194258)

Adam

fark
10-08-2003, 11:04 AM
THANKS A MILLION!
You guys and gals are absolutely great.
Thanks especially for the link to the reference page that will be very helpful in the future and keep me from asking more dumb questions.
Speaking of which do they have a similar reference pages for VBScript and ASP???
I keep asking questions on the other forum that I could easily answer with a reference like the javascript one. I keep relying on super simplistic sample scripts that teach me some of the stuff I need but not the more complex stuff I end up having to guess at that. Like in ASP finding out the form input name can be accessed with .Name. Took a lot of guessing and time to figure that out. Thanks again, lots and lots of help.

AdamGundry
10-08-2003, 12:35 PM
That's the Netscape reference, which does not cover M$ technologies like VBScript.

For VBScript, you might try the reference on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriVBScriptFundamentals.asp

I can't help you on an ASP reference, but maybe someone in that forum could.

Adam