Splitting a String


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Splitting a String

  1. #1
    Join Date
    Oct 2004
    Posts
    21

    Splitting a String

    Does java have a function that can split the string into an array where each element is a character of that string so like
    "abc" -> [0] => a [1] => b [2] => c ?

    I looked at the split function, but that seems to need something to seperate by like a comma.

    I was thinking doing a for loop like:
    String myString = "abc";
    int len = length(myString);
    int i;
    for(i=0; i<=len; i++)
    {
    b[] = myString.substring(i, i+1)
    }

    Im sure that this is prolly not the right syntax though, that is mostly what I am having trouble with because I've already worked a lot with php and am trying to learn java.

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    There is a method in the string class to do exactly what you want.

    Code:
     char[] charArray = someString.toCharArray();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center