is there any Java equivalent for C++'s "std::string::find_first_of"?
string string1( "This is a test string!");
int location = string1.find_first_of( "aeiou" );
//location is now "2" (the position of "i")
what is the easiest way to achieve this same functionality?
edit: also the proposed solution have to work for Android.
Without the use of an external library:
String string = "This is a test string!";
String letters = "aeiou";
Pattern pattern = Pattern.compile("[" + letters + "]");
Matcher matcher = pattern.matcher(string);
int position = -1;
if (matcher.find()) {
position = matcher.start();
}
System.out.println(position); // prints 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With