gla
asked on
transfer text to string array
I have a text like:
first
second
third
(with return)
and i want to transfer to a String array like:
String[] choices = {"first", "second", "third"};
first
second
third
(with return)
and i want to transfer to a String array like:
String[] choices = {"first", "second", "third"};
String choices = s.split("\n\r");
Read into a List then turn that into String[]
sorry typo, that should be:
String[] choices = s.split("\n\r");
String[] choices = s.split("\n\r");
ASKER
the text is in a jTextbox is this problem?
ASKER
sorry jTextarea...
Try
String[] tokens = ta.getText().split("\\s");
String[] tokens = ta.getText().split("\\s");
> the text is in a jTextbox is this problem?
no, just get the sytring using the textarea getText() method
no, just get the sytring using the textarea getText() method
ASKER
I have try with .split("\\s"); and .split("\n\r");
String [] to = jTextAreaTo.getText().spli t("\\s");
but not token
String [] to = jTextAreaTo.getText().spli
but not token
>>but not token
What do you mean by that?
What do you mean by that?
ASKER
not split
I don't understand. Are there always single words per line?
ASKER
yes
> I have try with .split("\\s"); and .split("\n\r");
what I suggested should work fine.
you don't want to use \\s as it will split on more than just new lines.
print out the text before you split it to verify the new lines are there
what I suggested should work fine.
you don't want to use \\s as it will split on more than just new lines.
print out the text before you split it to verify the new lines are there
ASKER
I have the following text for example:
1
2
34
liolios
geo lio
(different lines) in a jtextarea
and I want to put in a jlist with 5 lines but first must I put in String array is this clear
1
2
34
liolios
geo lio
(different lines) in a jtextarea
and I want to put in a jlist with 5 lines but first must I put in String array is this clear
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the complete java code is the follow:
javax.swing.DefaultListMod el listModel = new javax.swing.DefaultListMod el();
String [] cc = jTextAreaCC.getText().spli t("\n\r");
System.out.println(jTextAr eaCC.getTe xt());
System.out.println(cc.leng th);
listModel.removeAllElement s();
for (int i=0; i<cc.length; i++){
listModel.addElement(cc[i] );
}
jListCC.setModel(listModel );
and the result from previous example is one line in jList:
1234lioliosgeo lio
javax.swing.DefaultListMod
String [] cc = jTextAreaCC.getText().spli
System.out.println(jTextAr
System.out.println(cc.leng
listModel.removeAllElement
for (int i=0; i<cc.length; i++){
listModel.addElement(cc[i]
}
jListCC.setModel(listModel
and the result from previous example is one line in jList:
1234lioliosgeo lio
ASKER
yes objects working with:
textArea.getText().split(" [\n\r]");
thanks
textArea.getText().split("
thanks
>>
yes objects working with:
textArea.getText().split(" [\n\r]");
>>
IOW it's working with the code *I* posted ;-)
( [\n\r] is the same as [\r\n] )
yes objects working with:
textArea.getText().split("
>>
IOW it's working with the code *I* posted ;-)
( [\n\r] is the same as [\r\n] )
ASKER
yes but if your eyes is open then you will see the differed between the "\n\r" and "[\n\r]" the differed is the "[]" ok?
my english is not good but the java language is international!
my english is not good but the java language is international!
ASKER
CEHJ
I am realy sorry for my mistake yes you are right my eyes is not open
sorry very sorry!!!!
I correct this in the future!!
I am realy sorry for my mistake yes you are right my eyes is not open
sorry very sorry!!!!
I correct this in the future!!
>>the differed is the "[]" ok?
Precisely - and that is the difference that *my* code example introduced
Precisely - and that is the difference that *my* code example introduced
>>I correct this in the future!!
You could correct it now if you wanted - all i'd need to do is to get the question reopened ..;-)
You could correct it now if you wanted - all i'd need to do is to get the question reopened ..;-)
ASKER
yes,
sorry again the problem is with me...
sorry again the problem is with me...
ASKER
ok I repoen (new one)
You don't need to post a new question. Delete it please ;-). I'll get this reopened if you want
ASKER
ok
Have requested it be done - you don't need to do anything yet, other than to delete that new Q
ASKER
ok I deleted the new Q
Thanks
ASKER
CEHJ
I think I correct my mistake, sorry again...
I think I correct my mistake, sorry again...
:-)
No problem
No problem
Well they were posted at the same time, and I originally suggested using split().
He suggested reading into a List and then once he saw my suggestion he's changed his tune without any mention that I actually originally suggested it. Please reopen and split the points please.
He suggested reading into a List and then once he saw my suggestion he's changed his tune without any mention that I actually originally suggested it. Please reopen and split the points please.
>>then once he saw my suggestion he's changed his tune
My 'changing my tune' had nothing to do with anything you posted. It was based on gla's post beginning
>>I have the following text for example:
My 'changing my tune' had nothing to do with anything you posted. It was based on gla's post beginning
>>I have the following text for example:
ASKER
If you are agree (objects and CEHJ) and I agree to split the points
for my problem the correct comment is the CEHJ that posted at 04/28/2006 02:23PM EEST erlier than objects comment posted at 04/28/2006 02:25PM EEST 2 min later.
I am sorry objects the best way for all of us will was to split the points but I make a mistake against the CEHJ and I find a way to correct it.
for my problem the correct comment is the CEHJ that posted at 04/28/2006 02:23PM EEST erlier than objects comment posted at 04/28/2006 02:25PM EEST 2 min later.
I am sorry objects the best way for all of us will was to split the points but I make a mistake against the CEHJ and I find a way to correct it.
>>If you are agree (objects and CEHJ) and I agree to split the points
That's entirely up to you, but it's not customary to give points for incorrect answers or answers that are the same as ones posted previously
That's entirely up to you, but it's not customary to give points for incorrect answers or answers that are the same as ones posted previously