How to find char location in string

Hi

   Could someone advice me on how I could find the
location of a character within a string.

thanx
b3cfAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
lwinkenbConnect With a Mentor Commented:
String string = "this is a string";

int charIndex = string.indexOf('a');
0
 
CEHJCommented:
int index = "hello".indexOf('l'); // index = 2
0
 
lwinkenbCommented:
Also if you are looking for the index of a sub string you can use:

String string = "this is a string";

int subStringIndex = string.indexOf("string");
0
All Courses

From novice to tech pro — start learning today.