469,323 Members | 1,600 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

input string characters into an array

Folks
I am trying to input the characters of a string into an array. The array
needs to hold strings, so I need to convert the characters into strings and
then input them into the array. I run into a dereferencing error

StringBuffer buffy = new StringBuffer(strEntered);
for( i = 0; i < buffy.length(); i++ )
strTemp = (buffy.charAt( i ).toString); //throw dereferencing error in
compile
arrayEntered[ i ] = strTemp

Tried this a number of ways '(buffy.charAt( i ).toString); ' but either
throws exception or compiler cannot understand

Any suggestions would be appreciated.

Thanks
Harry
Jul 17 '05 #1
3 20132
"Harry" <ma*******@hotmail.com> wrote in message news:<Zl********************@comcast.com>...
Folks
I am trying to input the characters of a string into an array. The array
needs to hold strings, so I need to convert the characters into strings and
then input them into the array. I run into a dereferencing error
You need not convert the string to stringBuffer as String has charAt. StringBuffer buffy = new StringBuffer(strEntered);
for( i = 0; i < buffy.length(); i++ )
strTemp = (buffy.charAt( i ).toString); //throw dereferencing error in
compile buffy.charAt( i ) returns a character arrayEntered[ i ] = strTemp
Try this

char[] ch = new char[1];
for( i = 0; i <strEntered.length(); i++ ){
ch[0] = strEntered.charAt(i);
arrayEntered[i] = new String(ch);
}

Tried this a number of ways '(buffy.charAt( i ).toString); ' but either
throws exception or compiler cannot understand

Any suggestions would be appreciated.

Thanks
Harry

Jul 17 '05 #2
"Harry" <ma*******@hotmail.com> wrote in message news:<Zl********************@comcast.com>...
Folks
I am trying to input the characters of a string into an array. The array
needs to hold strings, so I need to convert the characters into strings and
then input them into the array. I run into a dereferencing error


hi
check this as well
use wrapper classes

for(int i
Character
Jul 17 '05 #3
hi Harry
sorry my previous post was incomplete ....
use wrapper classes

Character ch;
for(i=0;i<strEntrd.length();i++)
{
ch=new Character(strEntrd.charAt(i));
arrEntrd[i]=ch.toString();
}

or on-the-fly like

for(i=0;i<strEntrd.length();i++)
{
arrEntrd[i]=(new Character(strEntrd.charAt(i))).toString();
}

this should do the job
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by The Plankmeister | last post: by
3 posts views Thread by Harry | last post: by
4 posts views Thread by priyanka | last post: by
77 posts views Thread by arnuld | last post: by
24 posts views Thread by arnuld | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.