T
tuweiwen
Hi all, can anyone give me a hint on what approach I should take to
this simple problem: what is the quickest way to find out whether a
string contains another string? For example,
String a = "a very long string, UP TO 100k";
String b = "a string of two or three words";
//---- now I need to write this function
boolean a_contains_b (String a, String b) {
//I don't need to worry about the location of b, just want to know
//whether a has b inside it. Returns true or false
}
This function will be called Thousands of times in an app.
What's best way to handle this to achieve best performance?
Currently I am using "if (a.indexOf(b) !=-1) " in the above
"a_contains_b()" function. But I don't like it at all. It feels dumb,
isn't it? Do I have the wrong approach at the outset?
Thanks a lot. I appreciate your help.
this simple problem: what is the quickest way to find out whether a
string contains another string? For example,
String a = "a very long string, UP TO 100k";
String b = "a string of two or three words";
//---- now I need to write this function
boolean a_contains_b (String a, String b) {
//I don't need to worry about the location of b, just want to know
//whether a has b inside it. Returns true or false
}
This function will be called Thousands of times in an app.
What's best way to handle this to achieve best performance?
Currently I am using "if (a.indexOf(b) !=-1) " in the above
"a_contains_b()" function. But I don't like it at all. It feels dumb,
isn't it? Do I have the wrong approach at the outset?
Thanks a lot. I appreciate your help.