Forums Register Login

Case Insensative search

+Pie Number of slices to send: Send
i want to have a case insensative search...can anyone help me out.....
this is the code wich find only the word entered..(all caps or small or finds the word as present there)
private void doFind() {
String temp4 = "";
temp4 = ivjTextField1.getText();
String s3 = ivjTextArea1.getText();
int total = s3.length();

if(isfound ==false)
{
int ix = s3.indexOf(temp4);
if(ix >= 0)
{
lastindex = ix+temp4.length();
ivjTextArea1.select(ix, lastindex);
isfound = true;
oldString = ivjTextField1.getText();
}
} else
{
int ix2 = s3.indexOf(temp4, lastindex+1);
if(ix2>=0)
{
lastindex = ix2+temp4.length();
ivjTextArea1.select(ix2, lastindex);
// oldString = ivjTextField1.getText();
}
}

if(!temp4.equals(oldString)){
isfound = false;
doFind();
}

}
+Pie Number of slices to send: Send
To make your search "case insensitive", you could convert both the search string and the text you are searching to all upper or lower case and then compare them.
For example:

would yield a new string with value: "thisisastring"
+Pie Number of slices to send: Send
Why not just use String.equalsIgnoreCase(String)?

Originally posted by john klucas:
i want to have a case insensative search...can anyone help me out.....
this is the code wich find only the word entered..(all caps or small or finds the word as present there)
private void doFind() {
String temp4 = "";
temp4 = ivjTextField1.getText();
String s3 = ivjTextArea1.getText();
int total = s3.length();

if(isfound ==false)
{
int ix = s3.indexOf(temp4);
if(ix >= 0)
{
lastindex = ix+temp4.length();
ivjTextArea1.select(ix, lastindex);
isfound = true;
oldString = ivjTextField1.getText();
}
} else
{
int ix2 = s3.indexOf(temp4, lastindex+1);
if(ix2>=0)
{
lastindex = ix2+temp4.length();
ivjTextArea1.select(ix2, lastindex);
// oldString = ivjTextField1.getText();
}
}

if(!temp4.equals(oldString)){
isfound = false;
doFind();
}

}


+Pie Number of slices to send: Send
If u have lok at the code, i am not comparing two strings.
I have a text area where i am displaying the o/p.
so when the user wants to find anything..he just inputs that word...
and my serach function finds the index of that word and matches that in the text area.
its working fine if the users tries to find for a word which is exactly the same as it is present in the text area. So how can u do that??
+Pie Number of slices to send: Send
String temp4 = "";
temp4 = ivjTextField1.getText();
String s3 = ivjTextArea1.getText();
int total = s3.length();

Explain how that is not comparing 2 strings. You do a getText() from 2 different components returning Strings. Like a previous poster said convert them to all upper or lower then do your search.
temp4 = ivjTextField1.getText().toUpperCase();
String s3 = ivjTextArea1.getText().toUpperCase();
+Pie Number of slices to send: Send
thanx
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1060 times.
Similar Threads
Case Insensative search
Search Function for a TextArea.
some questions,please
How to update JList
Finding anagrams in a dictionary file using pre-fixes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:03:27.