This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Split a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Split a String" Watch "Split a String" New topic
Author

Split a String

Zahid, Butt
Ranch Hand

Joined: Feb 16, 2001
Posts: 100
Hi ALL
Does anyone know how to split a String into its constituent characters ??
e.g if you have a string say "saddle", how do I get hold of the character at position 1 or 2 ??
do I use the method charAt() ??? How do you use this method ???

Thanks in Advance.
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Yup.
If String s = "saddle", then s.charAt( 1 ) = 'a', s.charAt( 5 ) = 'e', and s.charAt( 10 ) gives a StringIndexOutOfBoundsException.
See also this link.
Art
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
String.charAt(int) returns the char at the specified location, just like it's defined:
String myString = new String("Matt");
char myChar = myString.charAt(0); //returns "M"
You can use String.toCharArray() to break a String down into an array of chars (char[]).
Originally posted by Zahid, Butt:
Hi ALL
Does anyone know how to split a String into its constituent characters ??
e.g if you have a string say "saddle", how do I get hold of the character at position 1 or 2 ??
do I use the method charAt() ??? How do you use this method ???

Thanks in Advance.


There's nothing more dangerous than a resourceful idiot. ---Dilbert
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Split a String
 
Similar Threads
Java String parsing help
need read a word of my project . Need help!!!
Reading data from a file and storing into array of strings problem
I always wonder about StringTokenizer ?
Converting String to an Array