Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the count of spaces before the string starts

Tags:

coldfusion

How do you get the number of spaces before a string starts in ColdFusion?

I mean, I have a string like this " Hello World!"

I want to get the count of spaces (in this case 3) before the word "Hello" starts.

like image 880
nasaa Avatar asked Jan 18 '12 14:01

nasaa


People also ask

How do you check the space at the beginning of a string?

trim() method trim space at starting and ending of a string by check unicode value '\u0020' (value of space)(most minimum value in unicode is '\u0020' = space) so it check every index from starting until get value greater than space unicode and also check from last until it get value greater than space and trim start & ...

How do you count string spaces?

To count the spaces in a string: Use the split() method to split the string on each space. Access the length property on the array and subtract 1. The result will be the number of spaces in the string.

How do you count leading spaces in Python?

To count the number of leading spaces in Python we have a really handy function called lstrip(). It gives us the output string by removing all the leading spaces present in our string. It also helps in removing defined function arguments present as leading characters in the string.

How do you count a string without spaces?

replace(/ /g,""); var length = newString. length . Just a quick way to guarantee no spaces are there.


1 Answers

I'm not too familiar with ColdFusion but considering this API you should be able to get the result you want with:

Len(str) - Len(LTrim(str))

But maybe there is a better solution :)

like image 87
rodion Avatar answered Oct 24 '22 14:10

rodion