Solved

How to find char location in string

Posted on 2003-10-30
3
525 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to add new optional parameter to JSP 1 49
table example 4 32
Custom Java Application connects to database: Which one of the 20? 4 35
Java: anonymous class 4 29
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

856 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