#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    64
    Rep Power
    11

    Convert char to string but got only the number


    example:
    char b='Z';
    textBox1->Text=Convert::ToString(b);

    I want that 'Z' is shown in the textBox but I get 90! What must I change to get the letter not the number?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Montreal, Canada
    Posts
    486
    Rep Power
    11
    I don't understang really much what you want to do !

    you have a CHAR and you want to add it in a text box ? then you should just do
    textbox.text = b

    or maybe if you want you could do a CSTR

    like texbox.text = cstr(b) no ?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Sheffield, UK
    Posts
    94
    Rep Power
    11
    hang on a sec.

    The only reason why you'd specify stuff as being strings or integers are such that the host program can use the appropriate resources and allocate sufficient overheads to accomplish whats its doing.

    The fact you've got a number and assigned it to a numeric value, does not detract from the fact that if you convert it to string, you'll still just have a number.

    Example:

    Dim texttest as string
    texttest = 1
    msgbox(texttest)

    will result in 1 being displayed, not an error message (even though it IS a number).

    Capish?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    64
    Rep Power
    11
    I found a way:

    [CODE]
    textBox1->Text=Convert::ToString(Convert::ToChar(b));
    [CODE]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    2
    Rep Power
    0

    The Reason


    .NET does not automatically assume chars are strings, because .NET works with unicode.

    The *proper* (nobody said easy) way to do it is to use the Encoding Classes in System.Text.Encoding to find the conversions.

    (c#)

    char b = 'Z';
    textBox1.Text = System.Text.Encoding.ASCII.GetString(b);

IMN logo majestic logo threadwatch logo seochat tools logo