Searching Sub String
Any idea how can I search a sub string from a String ignoring white spaces.
Ok, I need to Search a sub string ("for update") from a given String (henceforth Source String) but the condition is it might contain any number of white spaces between these two words (in source string).
So how can I search for "for update" in Source String ignoring any number of (but at least one) white spaces it might have in the source string.
(One way can be searching index of "for" than checking value at index+2 for "update"...and keep trying until i search through entire length of String...but I need some optimized way to do it as I need to check this virtually infinite times in my application)
[723 byte] By [
IrenicMan] at [2007-9-26 2:44:23]

you should "normalize" the string you are searching - that is - first scan it for white space and replace them with single spaces. Then convert it to lower case and search it for what you wish. You could use StringTokenizer -
StringTokenizer st = new StringTokenizer( toBeSearched, " \r\n\t" );
StringBuffer sb = new StringBuffer();
while( st.hasMoreTokens() ) sb.append( st.nextToken() + " " );
String toBeSearchedN = sb.toString().toUpperCase().toLowerCase();
String toSearchForN = toSearchFor.toUpperCase().toLowerCase();
boolean result = ( toBeSearchedN.indexOf( toSearchForN ) != -1 );
igarn at 2007-6-29 10:24:29 >

You can just test the existence of the 2 substring and that in between there's no other characters than space with a test like:
int indexFor= yourString.indexOf("for") ;
int indexUpdate= yourString.indexOf("update") ;
String substringBetween= yourString.substring(indexFor, indexUpdate-1);
if(indexFor > -1 && indexUpdate > -1 && indexFor < indexUpdate && substringBetween.trim().equals("for"))
{
//your code
}