开发者

how to trim a string without any spaces

How do I remove spaces and other whitespace characters from inside a string. I don't want to remove the space just from the ends of the 开发者_Go百科string, but throughout the entire string.


You can use a regular expression

<cfset str = reReplace(str, "[[:space:]]", "", "ALL") />


You can also simply use Coldfusion's Replace() (if you don't want to use regular expressions for some reason - but don't forget the "ALL" optional parameter.

I've run into this in the past, trying to remove 5 spaces in the middle of a string - I would do something like:

<cfset str = Replace(str, " ", "")/>

Forgetting the "ALL" will only replace the first occurrence so I would end up with 4 spaces, if that makes sense.

Be sure to use:

<cfset str = Replace(str, " ", "", "ALL")/>

to replace multiple spaces. Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜