Web Analytics Made Easy -
StatCounter Using String as Variable - CodingForum

Announcement

Collapse
No announcement yet.

Using String as Variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using String as Variable

    Hey, just a quick ques from a beginner. How do you define a string has a variable. For instance, we have double for decimals and such, and int for normal numbers, but what do we use if we want to define a string as a variable?

  • #2
    For c/c++......


    string

    ??

    string Hello;
    --or--
    char[20] Hello;

    Is that what you wanted?
    Last edited by mentalhorse; Oct 9, 2006, 09:15 PM.
    Why is a raven like a writing desk?

    Comment


    • #3
      It depends what programming language you're using.

      If you're using java it's

      Code:
      String myVarName;
      What language are you using?
      "To iterate is human, to recurse divine." -L. Peter Deutsch

      Comment


      • #4
        im using java, and thanks, Ill try what you suggested

        Comment


        • #5
          Okay, it worked. But my next, and hopefully last question is:

          When you need to user to input a double or integer, you use:

          variable = reader.nextDouble();

          or

          variable = reader.nextInt();

          what do you use for string?

          variable = reader.nextString doesn't work. Although I'm sure it's not supposed to. Any tips?

          Comment


          • #6
            what is reader? Is it of Scanner class? Or is it of BufferedReader ?
            "To iterate is human, to recurse divine." -L. Peter Deutsch

            Comment


            • #7
              I think he's talking scanner, if you call reader.next() should return the next string.

              Good luck;
              -Brando
              Why using tables for eating is stupid!

              Comment


              • #8
                Originally posted by Brandoe85 View Post
                I think he's talking scanner, if you call reader.next() should return the next string.

                Good luck;
                Even so, his problem may be in the way he's creating the Scanner, which is why I ask
                "To iterate is human, to recurse divine." -L. Peter Deutsch

                Comment


                • #9
                  If reader.nextDouble(); and reader.nextInt(); work I will assume he is creating it correctly.
                  -Brando
                  Why using tables for eating is stupid!

                  Comment


                  • #10
                    That would be because I misunderstood his second post and read it in a completely different way.
                    "To iterate is human, to recurse divine." -L. Peter Deutsch

                    Comment

                    Working...
                    X