Page 1 of 1

splitting a java string into a character array

Posted: Thu Sep 26, 2002 5:45 am
by ozmodiar
Hi,

I need to split a string into a character array in java. Can anyone help me. All I can find is splitting a string on spaces.

Thank you

Ozmodiar

Posted: Thu Sep 26, 2002 8:13 am
by f1nutter
The function you need takes the general form char[] toCharArray()

Code: Select all

import java.io.*;
import java.lang.*;

public class ArrayTest
{
    public static void main(String argsї]) throws Exception
    {
        String myString = "hello";

        char myCharArrayї] = new charї10];

        myCharArray = myString.toCharArray();

        System.out.println(myCharArray);

        System.exit(0);
    }
}
You can then search java.sun.com documentation for toCharArray for more examples.

Posted: Thu Sep 26, 2002 8:13 am
by volka
with google I found http://members.ozemail.com.au/~dcrombie/javascript/chap10.html. Sorry, usually I prefer http://selfhtml.teamone.de/ but it's in german.
  • You're probably looking for
  • .charAt()
  • .split()
  • or even match()
The Java-class String also support .getBytes() but I'm not sure JavaScript does.

edit: once again: I'm tooooooo slow