Monday, 19 August 2013

Splitting strings using Ruby ignoring certain characters

Splitting strings using Ruby ignoring certain characters

I'm trying to split a string and counts the number os words using Ruby but
I want ignore special characters.
For example, in this string "Hello, my name is Hugo ..." I'm splitting it
by spaces but the last ... should't counts because it isn't a word.
I'm using string.inner_text.split(' ').length. How can I specify that
special characters (such as ... ? ! etc.) when separated from the text by
spaces are not counted?
Thank you to everyone, Kind Regards, Hugo

No comments:

Post a Comment