Thread: Converting a text box value into a character array?

  1. #1
    Registered User
    Join Date
    Jul 2006

    Red face Converting a text box value into a character array?

    I'm using a .NET Forms Application, and I have a text box that I want to copy the value of to an array of char's. I'll be the first to admit, I'm quite inexperienced with .NET, and honestly, C/C++ in general.

    Maybe I'm just lazy, but I can't figure it out.

    My character array is char sVModel[64], in struct SGlockInfo sglock_info.
    My text box is this->ModelNameViewPistol.

    I've done it one way:
    I'm sure that's kinda sleazy, but...

    The trouble is, I can't seem to do it the other way around. Am I just missing something? I suppose I should wait until tomorrow to be working on a non-negative amount of sleep, but when I come across a problem, my mind refuses to let it rest.

    Please, someone point out whatever it is that my mind refuses to comprehend.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Seattle, WA
    To create a System::String from a char array you can probably do:
    System::String^ str = gcnew System::String(chArray);
    The other way around (System::String to char array) is probably more difficult, especially since (as far as I know) System::String is only unicode

    This thread might be able to help you.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."

  3. #3
    train spotter
    Join Date
    Aug 2001
    near a computer
    Is there a reason why you are mixing char arrays and strings?

    Why not just use strings?

    or try....

    char szBuffer[256]={0};
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Jul 2006
    The reason I'm mixing these things is because the program that I need the text for requires the char array.

    I guess I forgot to mention this, but this->ModelNameViewPistol is 'System::Windows::Forms::TextBox', thus GetWindowText is not a member of it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Using a character array in a switch question.
    By bajanElf in forum C Programming
    Replies: 10
    Last Post: 11-08-2008, 08:06 AM
  3. Converting character array to integer array
    By quiet_forever in forum C++ Programming
    Replies: 5
    Last Post: 04-02-2007, 05:48 AM
  4. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  5. New Theme
    By XSquared in forum A Brief History of
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM