Split a string into an array consisting of a single letters.

Is their anyway to split a string into an array where each index contains only one letter?

Ive read about the tokinizer but this splits words from what ive read. Ty for the help.

[191 byte] By [krrose27a] at [2007-11-27 10:34:56]
# 1

Have a look at String's toCharArray() method.

prometheuzza at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 2

> Have a look at String's toCharArray() method.

and if you want a String[] array rather than a char[] array then you could useString[] asStringArray = "abcde".split("(?<=.)(?=.)");

One minor problem, this will give you an array of length 1 containing an empty string when the original is empty.

sabre150a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 3

i got it, ty. I have it in another thread, trying to figure out how to use it todo what i want lol.

krrose27a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 4

> i got it, ty. I have it in another thread, trying to

> figure out how to use it todo what i want lol.

Tut tut tut! Cross posting just wastes our time. Please don't do it!

sabre150a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 5

Ok sry i have no clue what to name this, sry.

Heres the code.

public static void sendWord(Robot robot, String word){

String wordUp = word.toUpperCase();

char [] letters = wordUp.toCharArray();

for(int i = 0; i < letters.length; i++){

System.out.println(letters[i]);

pressKey(robot, KeyEvent.VK_letters[i]);

}

}

The problem is apperant. the wonderfull pressKey(robot, KeyEvent.VK_letters);

How should i go about doing this? This seems pretty self explanitory, but it might not be so if i need to explain the code i will.

Message was edited by:

krrose27

krrose27a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 6

What don't you understand about "Please don't cross post"?

http://forum.java.sun.com/thread.jspa?threadID=5194900&tstart=0

sabre150a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 7

It's unclear (to me) what you're trying to do.

prometheuzza at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 8

.. i did that before she said that.

krrose27a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 9

im trying to take each latter of the word that i separate and genrate its key code. if u need me to comment each line i can.

krrose27a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 10

the ommented code

public static void sendWord(Robot robot, String word){

String wordUp = word.toUpperCase();// convert the passed strin to caps.

char [] letters = wordUp.toCharArray();//split each letter in the word into its own char.

for(int i = 0; i < letters.length; i++){//a for loop

System.out.println(letters[i]);//out print the current letter

pressKey(robot, KeyEvent.VK_letters[i]);//try and generate the keycode for that letter, the thing wihch i have no clue todo.

}

}

krrose27a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 11

Just pass the characters through then. ...VK_R is the same as the char R.

prometheuzza at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 12

huh?

krrose27a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 13

> huh?

huh?

Edit: never mind: I'm not going to take the trouble anymore after an uninterested huh?.

Message was edited by:

prometheuzz

prometheuzza at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 14

> Just pass the characters through then. ...VK_R

> is the same as the char R.

R dosent mean the same as vk_r their is no just r.

krrose27a at 2007-7-28 18:32:02 > top of Java-index,Java Essentials,New To Java...
# 15

> R dosent mean the same as vk_r their is no just r.

System.out.println(java.awt.event.KeyEvent.VK_R == 82);

System.out.println(java.awt.event.KeyEvent.VK_R == 'R');

prometheuzza at 2007-7-28 18:32:06 > top of Java-index,Java Essentials,New To Java...
# 16

well if i put KeyEvent.R in eclipse it, and if i run it it says theirs and unresolved compilation problem. SO apperantly not.

krrose27a at 2007-7-28 18:32:06 > top of Java-index,Java Essentials,New To Java...
# 17

> well if i put KeyEvent.R in eclipse it, and if i run

> it it says theirs and unresolved compilation problem.

> SO apperantly not.

You seem to have all the answers yourself already. Good luck.

prometheuzza at 2007-7-28 18:32:06 > top of Java-index,Java Essentials,New To Java...
# 18

wow, im just saying that java wont let it compile.

krrose27a at 2007-7-28 18:32:06 > top of Java-index,Java Essentials,New To Java...
# 19

> > well if i put KeyEvent.R in eclipse it, and if i

> run

> > it it says theirs and unresolved compilation

> problem.

> > SO apperantly not.

>

> You seem to have all the answers yourself already.

> Good luck.

im sorry i just relised i miss understood u u meant the letter without the keyevent stuff before it, thats why it wasnt workin. Sry man, i appologise.

krrose27a at 2007-7-28 18:32:06 > top of Java-index,Java Essentials,New To Java...