A
Alex Zorin
Well, I'm not having trouble or anything, but I'm wondering why the String
class doesnt have a contains method?
eg
public boolean contains(String str)
So you could write
if(myString.contains("poo" ) {
/ / Do whatever
}
Right now the only way to do this (or easiest at least) is to use
indexOf(String s) and see if the result isn't '-1'. So I propose:
public boolean contains(String full, String searched) {
if(full.indexOf(searched) != -1)
return true;
else { return false; }
}
Of course, you could make it so it extends the String class, but just an
example? I think this form of String manipulation would be most useful in
many cases..
Anyone else agree it'd be a useful addition?
}
class doesnt have a contains method?
eg
public boolean contains(String str)
So you could write
if(myString.contains("poo" ) {
/ / Do whatever
}
Right now the only way to do this (or easiest at least) is to use
indexOf(String s) and see if the result isn't '-1'. So I propose:
public boolean contains(String full, String searched) {
if(full.indexOf(searched) != -1)
return true;
else { return false; }
}
Of course, you could make it so it extends the String class, but just an
example? I think this form of String manipulation would be most useful in
many cases..
Anyone else agree it'd be a useful addition?
}