Monday, July 27, 2009

[jQuery] Re: How to deterine number of words in a string?

The most important part in my string is..it contains chinese characters...

For an example

I come from 香港<---so totally 5 words instead of length = 15

Thx all of you.




On Tue, Jul 28, 2009 at 7:23 AM, RobG <robgbne@gmail.com> wrote:



On Jul 28, 5:09 am, Liam Byrne <l...@onsight.ie> wrote:
> A letter count is FAR easier - just get the string's length.

The length of the string will give you a *character* count. I would
not inlcude punctuation, white space, etc. in a *letter* count.  For
number of letters, try:

 s.replace(/[^a-zA-Z]/g,'').length;


--
Rob

No comments: