Solved

How to find char location in string

Posted on 2003-10-30
3
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

749 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