Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: method to chop off the empty space in Javascript


Message #1 by "miaoju luo" <luomiaoj@h...> on Thu, 12 Oct 2000 17:43:46 GMT
Thanks, Denis and Imar. It works!!! You make my day.


>From: "Denis" <yahden@y...>
>Reply-To: "javascript" <javascript@p...>
>To: "javascript" <javascript@p...>
>Subject: [javascript] RE: method to chop off the empty space in Javascript
>Date: Thu, 12 Oct 2000 14:24:37 -0500
>
>use regular expressions or write a trim funcion that loops thru the string
>and takes out the spaces
>FUNCTION:
>function trim(sString)
>{
>	sTrimmedString = "";
>	if (sString != "")
>	{
>		var iStart = 0;
>		var iEnd = sString.length - 1;
>		var sWhitespace = " \t\f\n\r\v";
>
>		while (sWhitespace.indexOf(sString.charAt(iStart)) != -1)
>		{
>			iStart++;
>			if (iStart > iEnd)
>				break;
>		}
>
>		// If the string not just whitespace
>		if (iStart <= iEnd)
>		{
>			while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
>				iEnd--;
>			sTrimmedString = sString.substring(iStart,++iEnd);
>		}
>	}
>	return sTrimmedString;
>}
>
>REGULAR EXPRESSIONS:
>STRING=STRING.replace(/^[\s]+/g,"");
>STRING=STRING.replace(/[\s]+$/g,"");
>
>you can use anyone only reg exp is not supported in the earlier browsers
>
>
>
>
>-----Original Message-----
>From: miaoju luo [mailto:luomiaoj@h...]
>Sent: Thursday, October 12, 2000 12:44 PM
>To: javascript
>Subject: [javascript] method to chop off the empty space in Javascript
>
>
>How do I get rid of empty space from text field in Javascript. In Visual
>Basic, I use Trim(strName) to get rid of empty space in the textField,
>(LTrim(strNmae) for LeftTrim only and RTrim(strName) for RightTrim only).
>
>Thanks for any recommandation!!
>
>


  Return to Index