Solved

How to find char location in string

Posted on 2003-10-30
3
522 Views
Last Modified: 2010-03-31
Hi

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

thanx
0
Comment
Question by:b3cf
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
lwinkenb earned 50 total points
ID: 9652161
String string = "this is a string";

int charIndex = string.indexOf('a');
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9652164
int index = "hello".indexOf('l'); // index = 2
0
 
LVL 5

Expert Comment

by:lwinkenb
ID: 9652167
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now