Frage

I've been looking for answer regarding my question but I cannot find one or maybe I'm not just using the right terms when searching.

My question is, how can I distribute string entered in an editText to an array?

This is about my porter2 stemming project. I need to distribute the strings entered in the EditText field to an array so i can scan whether x in array[x] is vowel or not.

Ex. String in EditText field = "dog".

Array should be:

array[0] = d
array[1] = o
array[2] = g

I'm sorry that i cannot give a code because I really don't have any idea how to code this one. Thank you so much everyone. :)

War es hilfreich?

Lösung

You can use use .split() with an empty ("") string input:

String text = yourEditText.getText().toString();
String[] letters = text.split(""); // Split by empty string to be in an array
// letters == { "", "d", "o", "g" }
//              ^ Note that this has an empty string element at the front; that's just a byproduct of how split() works.

If you want a char array instead, it's much easier to use .toCharArray():

String text = yourEditText.getText().toString();
char[] letters = text.toCharArray();
// letters == { 'd', 'o', 'g' };

Personally I'd use the second one; letter == 'a' is a much faster operation than letter.equals("a").

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top