?
Solved

How to find char location in string

Posted on 2003-10-30
3
Medium Priority
?
529 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 200 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

771 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