• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable to string to command

 
donald croswell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,
I am trying to get a variable to concatinate to a string then use that string as a command like this:
newx = place + "[" + num + "]";
Where place = "ones" and num = "8".

So my line new line is:
newx = ones[8];
This will make newx equal to the static string array "ones" in the "8" place.
I can get the concatination to the string but it doesn't treat the string like a command.
Thanks for the help!
Don
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, all you did was assign the String value "ones[8]" to newx. You cannot use a String Object to represent a variable. If you want to assign the value in ones[8] to newx you have to use the variable name. If num is a String you'll have to convert it to an int first.

If places can hold other values besides "ones" you need to put this in a controll structure to determine which array to place it in.

------------------
Hope This Helps
Carl Trusiak, SCJP2
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic