Solved

How to find char location in string

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GUI builder for Eclipse? 8 35
HSSFWorkbook cannot be resolved error 10 69
how to add new optional parameter to JSP 1 41
mysql jsp example issue 32 33
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 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