473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

input characters from a string 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 5002
What type/object does charAt() return?
Harry wrote:
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 #2
"Harry" <ma*******@hotmail.com> skrev i meddelandet
news:0O********************@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

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


charAt returns a primitive char. There is no such thing as a toString for
primitives. Try this:
strTemp = (new Character(buffy.charAt( i )).toString);
Finally an advice. If you use a JavaIDE you will have access to "code
insight", which will tell you which methods can be used at a certain point
in your code.
/Josef
Jul 17 '05 #3
Try
StringBuffer buffy = new StringBuffer(strEntered);
for( i = 0; i < buffy.length(); i++ )
strTemp = (buffy.charAt( i ) + "");
arrayEntered[ i ] = strTemp;
"Harry" <ma*******@hotmail.com> skrev i meddelandet
news:0O********************@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

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

charAt returns a primitive char. There is no such thing as a toString for
primitives. Try this:
strTemp = (new Character(buffy.charAt( i )).toString);
Finally an advice. If you use a JavaIDE you will have access to "code
insight", which will tell you which methods can be used at a certain point
in your code.
/Josef


Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: The Plankmeister | last post by:
Hi... What's the best method of validating input characters? I would like to prevent users submitting exotic characters (such as those acquired on Windows Systems by pressing ALT+) and thought...
3
by: Harry | last post by:
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...
43
by: SLH | last post by:
hi people. im trying to validate input received via a text area on an ASP page before writing it to a database. i cant use client side javascript due to policy, so it all has to happen on the...
4
by: priyanka | last post by:
Hi, I want to input a string from command line. I use the following program to input the string. #include<stdio.h> int main(){ char input;
6
by: TheRealDan | last post by:
Hi all. I'm having a problem with a special characters. I have php script that reads from an xml file and writes to a mysql db. It's a script called phptunest that I found on the net, although the...
59
by: David Mathog | last post by:
Apologies if this is in the FAQ. I looked, but didn't find it. In a particular program the input read from a file is supposed to be: + 100 200 name1 - 101 201 name2 It is parsed by reading...
77
by: arnuld | last post by:
1st I think of creating an array of pointers of size 100 as this is the maximum input I intend to take. I can create a fixed size array but in the end I want my array to expand at run-time to fit...
24
by: arnuld | last post by:
I have a function named getword that read every single input from std. input. WHAT I WANTED: I want it read the word if it has less than or equal to 30 characters. Anything else beyond that...
209
by: arnuld | last post by:
I searched the c.l.c archives provided by Google as Google Groups with "word input" as the key words and did not come up with anything good. C++ has std::string for taking a word as input from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.