For a rather complex search function I need to get the first letter of each word entered into an input field.
At first glance this may not seem like a big problem if every word is neatly seperated by a space.
Although people can enter whatever they want into the field I only want to work with the words that start with a-z or A-Z.
I’m having a bit of trouble figuring out how I can determine if a character in the string falls into this selection.
One of the possibilities is to use charCodeAt(), but that’s rather rough. I can walk through the string using indexOf() but I may have trouble finding the next word if characters other than a space come into play.
Say I have a string like: Super “big hamburger”
(notice the ‘accidental’ double space after super)
What I want to get out of it is: Super big Hamburger
which I later decrease to: s b h
If any functions come to mind that could help me figure this out, I’d appreciate the feedback.
– the full story –
I’m turning a php/mysql search into a standalone flash search. The database contents become xml files. a.xml would for instance have all words starting with ‘a’. Each entry gives me a key that brings me to say 24.xml which then contains all articles that contain that word.
I know it’s a bit of an odd thing, but client is king so I have to make this work.