File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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