473,394 Members | 1,840 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,394 software developers and data experts.

REQ Assistance string to array

I'm trying to take a string, from a JOptionPane and change it into a
char array in which I can manipulate the characters as ASCII with
other char arrays and append into a new string. I've declared
tempArray as char[], and uPhrase is a string. this is a simple
vinere encryption program....not as easy for the beginner as it seems.
I have to take a key phrase, a test phrase and return an encrypted
phrase based on a ascii shift method.
any help is muach appreciated.

TIA
public char[] toCharArray()
{
char[] tempArray = new char[99];
tempArray = String.toCharArray(uPhrase);
return tempArray;
}

Jul 17 '05 #1
5 6763
registered user wrote:
public char[] toCharArray()
{
char[] tempArray = new char[99];
tempArray = String.toCharArray(uPhrase);
return tempArray;
}


As an aside, you don't need the line 'char[] tempArray = new char[99];'
tempArray is just a reference. When you call
String.toCharArray(uPhrase), the toCharArray() method is going to
initialize a new array and return a reference to it, which will be
assigned to tempArray. As a result, the 99-character array you allocated
will no longer have any references to it, and it will be garbage
collected.

Incidentally, you don't even need this toCharArray method in your class.
Just call String.toCharArray(uPhrase) in your code instead of calling
this toCharArray() method you created.

Joe

Jul 17 '05 #2
Joe Attardi wrote:
Incidentally, you don't even need this toCharArray method in your class.
Just call String.toCharArray(uPhrase) in your code instead of calling
this toCharArray() method you created.


Unless of course uPhrase is a private instance variable, in which case
the user-constructed toCharArray() just becomes a wrapper over that
functionality.
Jul 17 '05 #3
Chris Dutton wrote:
Unless of course uPhrase is a private instance variable, in which case
the user-constructed toCharArray() just becomes a wrapper over that
functionality.


Good call, Chris. I didn't think of that case.

Joe
Jul 17 '05 #4
Joe Attardi wrote:
Chris Dutton wrote:
Unless of course uPhrase is a private instance variable, in which case
the user-constructed toCharArray() just becomes a wrapper over that
functionality.

Good call, Chris. I didn't think of that case.


Of course, it might be that the better answer is to have the class in
question provide a toString() method, in which case it could presumably
be used tramsparently with String.toCharArray().
Jul 17 '05 #5
"registered user" <no**@hotmail.com> wrote in message
news:e2********************************@4ax.com...
I'm trying to take a string, from a JOptionPane and change it into a
char array in which I can manipulate the characters as ASCII with
other char arrays and append into a new string. I've declared
tempArray as char[], and uPhrase is a string. this is a simple
vinere encryption program....not as easy for the beginner as it seems.
I have to take a key phrase, a test phrase and return an encrypted
phrase based on a ascii shift method.
any help is muach appreciated.

TIA
public char[] toCharArray()
{
char[] tempArray = new char[99];
tempArray = String.toCharArray(uPhrase);
return tempArray;
}

Maybe I'm confused. What's wrong with "uPhrase.toCharArray()"? Also, unless
you know something I don't, there is no static toCharArray method in String.
Jul 17 '05 #6

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

Similar topics

4
by: MLH | last post by:
I apologize in advance to forum readers noticing this somewhat redundant post. I fear that my Subject Heading was ill-chosen in earlier post I made on this topic. Am hoping that a clearer Subject...
1
by: Dalan | last post by:
I'm experiencing a Query Syntax Error with an Access 97 Db. Actually, the query performs as expected when adding any new records or editing existing ones and even deleting records, EXCEPT when the...
2
by: Rolan | last post by:
Need some assistance with regard to the following basic Function to change digits to text, i.e., 295.78 = RTELG. Any suggestions or ideas will be appreciated. Thanks. Function dtt(Cost As...
0
by: Richard Mathis | last post by:
My problem is rather complicated (for me), so I'm going to post my problem here as well as what I've done so far to solve my problem. Any assistance would be appreciated. I originally posted this...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
6
by: sandy | last post by:
I am working on an assignment which is a 'discrete event simulation'. I have a class called event, I need to add it to a priority queue and I cannot for some reason. I am sure it's the syntax... ...
0
by: satan | last post by:
I need to call the recursive binarySearch method from my OrderedArrayList class into my main program public abstract class ArrayListClass { protected int length; //to store the...
13
by: B. Williams | last post by:
I have written some code to accept input and place this input at the beginning or end of a list, but I need assistance including a class so that it will allow input of a phone number that is...
4
by: pmactdot | last post by:
Hi, I'm looking for some assistance on a case study...I have two arrays <head>: one for daily special dish name, second for the daily dish description, then I have two document.write: a daily...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.