splitting a java string into a character array

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
ozmodiar
Forum Commoner
Posts: 35
Joined: Sat Jun 01, 2002 6:29 am
Location: Dublin, Ireland

splitting a java string into a character array

Post 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
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Post Reply