About String

Hi,

If I have:

String strSearch = txtf.getText();

String str = elseString;

str.startsWith(strSearch);

I know to fined start with, but it is not case sencitive.

I don't anderstend how to use this:

str.matches("(?i)'"+strSearch+"'.*");

why I have (?i) ?

Thanks

Yael

[383 byte] By [yael800a] at [2007-11-26 12:23:07]
# 1
what you want?!!! you want startsWith with no case sensitive? or what?
Ayman_javaa at 2007-7-7 15:22:41 > top of Java-index,Java Essentials,Java Programming...
# 2
Why don't u just uppercase/ lowercase both your str and strSearch? In that case, u don't need to worry about case sensitivity.
khookha at 2007-7-7 15:22:41 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks,but if I will want to search something like *str*..?I don't know how to use with this function.str.matches("(?i)'"+strSearch+"'.*");
yael800a at 2007-7-7 15:22:41 > top of Java-index,Java Essentials,Java Programming...
# 4
there are methods like indexOf() in the String class that can help you to achieve searching *str*.... try looking at the String class Javadocs
khookha at 2007-7-7 15:22:41 > top of Java-index,Java Essentials,Java Programming...
# 5
But why don't use str.matches? it is not good method?
yael800a at 2007-7-7 15:22:41 > top of Java-index,Java Essentials,Java Programming...
# 6

> But why don't use str.matches? it is not good method?

"matches" means that you're trying to find out whether a given String applies to a certain pattern. All you want to now is whether some substring exists. matches() would not only be overkill, but also obviously more difficult to understand (you prove it yourself) and slower.

CeciNEstPasUnProgrammeura at 2007-7-7 15:22:41 > top of Java-index,Java Essentials,Java Programming...
# 7
it is not that matches() is not a good method, it is just that you must undestanding how regular expressions work. If you have a hard time understanding it, find something similar and easier to understand. It will also help you when you need to debug your codes.
khookha at 2007-7-7 15:22:41 > top of Java-index,Java Essentials,Java Programming...
# 8
read about regular expression http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html#sum
Ayman_javaa at 2007-7-7 15:22:41 > top of Java-index,Java Essentials,Java Programming...
# 9
Thanks :)
yael800a at 2007-7-7 15:22:41 > top of Java-index,Java Essentials,Java Programming...