| | |
Parse String
Thread Solved
![]() |
•
•
Join Date: Sep 2008
Posts: 46
Reputation:
Solved Threads: 0
Hi,
Basically, I'm trying to parse a string into a char for submitting into an array, this is what I have so far:
The bottom lines yields an error...is this possible to do?
Basically, I'm trying to parse a string into a char for submitting into an array, this is what I have so far:
Java Syntax (Toggle Plain Text)
String strVariable; Char charVariable; strVariable = "Some String"; charVariable = String.ParseString(strVariable);
The bottom lines yields an error...is this possible to do?
•
•
•
•
Hi,
Basically, I'm trying to parse a string into a char for submitting into an array, this is what I have so far:
Java Syntax (Toggle Plain Text)
String strVariable; Char charVariable; strVariable = "Some String"; charVariable = String.ParseString(strVariable);
The bottom lines yields an error...is this possible to do?
first of all, it's no use to parse a String to a String, secondly, you can not put a String object in a char
•
•
Join Date: Sep 2008
Posts: 46
Reputation:
Solved Threads: 0
Makes sense.
Well, to help with the situation, I'm trying to get text from a text field.
Works Fine:
Error:
I'm trying to do this because I'm trying to input data into a portion of an array that requires the data to be of a char data type.
Well, to help with the situation, I'm trying to get text from a text field.
Works Fine:
Java Syntax (Toggle Plain Text)
String strVariable = jTextField1.getText();
Error:
Java Syntax (Toggle Plain Text)
Char charVariable = jTextField1.getText();
I'm trying to do this because I'm trying to input data into a portion of an array that requires the data to be of a char data type.
it makes sense that you get this error. the getText() method of the JTextFields return a String object.
what you can do, is :
now you have the same data, but as an array of chars, which you can address seperately
instead of a String object
what you can do, is :
Java Syntax (Toggle Plain Text)
String strVariable = jTextField1.getText(); Char[] allChars = strVariable.toCharArray();
now you have the same data, but as an array of chars, which you can address seperately
Java Syntax (Toggle Plain Text)
char firstChar = allChars[0]; char secondChar = allChars[1]; ...
instead of a String object
•
•
Join Date: Sep 2008
Posts: 46
Reputation:
Solved Threads: 0
Sorry, I left out some important information.
I have classes set up and the data is being put into classes in the following format:
So I tried what you suggested, but I'm not sure how I would implement that.
I have classes set up and the data is being put into classes in the following format:
Java Syntax (Toggle Plain Text)
array[index].setVariable(variable);
So I tried what you suggested, but I'm not sure how I would implement that.
since I have no idea what kind of object array is an array of, or what kind of type variable has ... how do you think I can help you with it?
if the point is to have this variable as an element in the array though, you're going about it the wrong way. if so, you should do
if you want a variable within the element of array to be set to variable, you'll have to be just a tad more specific about what you're doing.
if the point is to have this variable as an element in the array though, you're going about it the wrong way. if so, you should do
Java Syntax (Toggle Plain Text)
array[index] = variable;
if you want a variable within the element of array to be set to variable, you'll have to be just a tad more specific about what you're doing.
•
•
Join Date: Sep 2008
Posts: 46
Reputation:
Solved Threads: 0
Alright, I'll see what I can do about being more specific, I'm finding it a bit hard to explain.
Hmm, well I had to make a UML Class Diagram where each class in the diagram had Attributes in it, and with each attribute is a "get" and a "set". The gets and sets are accessible through arrays. Here's the code from a class that was compiled from the diagram:
So to get/set from this class I setup an array:
To get:
To set:
I hope this helps
Hmm, well I had to make a UML Class Diagram where each class in the diagram had Attributes in it, and with each attribute is a "get" and a "set". The gets and sets are accessible through arrays. Here's the code from a class that was compiled from the diagram:
Java Syntax (Toggle Plain Text)
public class GuestPass { private int guestNum; private int numLeft; public GuestPass () { } public int getGuestNum () { return guestNum; } public void setGuestNum (int val) { this.guestNum = val; } public int getNumLeft () { return numLeft; } public void setNumLeft (int val) { this.numLeft = val; } public void getGuestCode () { return guestCode; } public void setGuestCode (char val) { this.guestCode = val; } }
So to get/set from this class I setup an array:
Java Syntax (Toggle Plain Text)
static GuestPass guests[] = new GuestPass[50];
To get:
Java Syntax (Toggle Plain Text)
guests[index].getGuestCode();
To set:
Java Syntax (Toggle Plain Text)
guests[index].setGuestCode('T');
I hope this helps
the getters and setters are accessible through the instances of GuestPass that you've put in an Array.
now, since I still don't know what exactly it is supposed to do, I'm taking a wild guess here:
now, since I still don't know what exactly it is supposed to do, I'm taking a wild guess here:
Java Syntax (Toggle Plain Text)
String strVariable = jTextField1.getText(); Char[] allChars = strVariable.toCharArray(); GuestPass[] allGuests = new GuestPass[strVariable.length()]; for(int i = 0; i < strVariable.length(); i++){ GuestPass help = new GuestPass(); help.setGuestCode(allChars[i]); allGuests[i] = help; }
![]() |
Similar Threads
- c-string (C++)
- Splitting a String (Python)
- String manipulations (C)
- Java - enter string (Java)
- File parsing and then parsing the string (C)
- Help with string (C)
- Converting a String into an integer array (C)
- string parser (Shell Scripting)
- Something about String.split("-"); problem (Java)
Other Threads in the Java Forum
- Previous Thread: finding names of workgroup computers
- Next Thread: Recursively reverse an array
| Thread Tools | Search this Thread |
6 @param actuate affinetransform android api applet application arc array automation balls binary bluetooth bold business c++ class client code codesnippet collections color compare component coordinates count database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework html ide ideas image ingres intersect invokingapacheantprogrammatically j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list map method methods mobile mysql netbeans nextline object parameter php pong problem producer program project projectideas recursive replaysolutions rim scanner sell server set size sms sql sun swing swt terminal threads tree web websites windows





