This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a set of forbidden and special words placed in a properties file . then when user enters a String , i need to compare the given string with the existing list from properties file and evaluate it . for that i need to check for blank spaces and special characters and white spaces . can you advise me how to do this ?like which is the best option?
(I used _ for blank here to make things format beter ...)
You may be asking how to find a word and not a word fragment. You'd want to include "_word." and "_word\n" and "(word)" and maybe "_word's_" but not "wordsmith" or "sword". Is that right?
You might try translating all non-alpha characters to blanks in your text, then use plain indexOf for "_word_". Add an extra blank to the beginning and end of the text just for good measure. Look at String.translateAll() with a regular expression (see Pattern javadoc) that matches all non-alpha. Translate the whole text to lowercase, too. [ October 20, 2004: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jul 30, 2003
Hi, Stan -
That's a good technique, very flexible. Sometimes I forget that Java supports regex and that I don't have to resort to Perl to use them!