Forums Register Login

Converting String to String []

+Pie Number of slices to send: Send
How can I convert a String to a String array? I am grabbing a String from a JTextField; this value has to go into a method that needs it in String[] format. Thanks
+Pie Number of slices to send: Send
What about this:
SearchString = searchField.getText(); //from JTextField
String[] strings = SearchString.split("\\s"); //split on space
+Pie Number of slices to send: Send
Yes, split() is probably exactly what you want. If indeed splitting on whitespace is what you need. Note that you might want to split on "\\s+" instead. Otherwise if you have any consecutive whitespaces, like say a space followed by a newline (a common occurance), your array would have an extra empty string "" representing what's between the space and the newline.
+Pie Number of slices to send: Send
If you simply want to pass in the entire string as a single-element array:

You could do the above in one statement, but this shows how you allocate the array and set the value.
Acetylsalicylic acid is aspirin. This could be handy too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 444 times.
Similar Threads
Looking for correct data type to take in stream of xml
how to sovle these two errors~~~help~~~
amount currency datatype
Please Comment on Data Section
SQL Data Types
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:21:15.