Results 1 to 5 of 5

Thread: System.Char[]

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    System.Char[]

    I forgot! If I have an array of chars[], how can I show them in a textbox without System.Char[] being shown when I do:

    theChars.ToString();

    ?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: System.Char[]

    Use Encoding.GetString().

    Example:
    Code:
    string s = (new System.Text.ASCIIEncoding()).GetString(chars);
    Last edited by penagate; Sep 12th, 2006 at 02:08 PM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: System.Char[]

    that doesnt work and is that not overkill?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: System.Char[]

    Sorry.
    This works:
    Code:
    char[] chars = { 'H', 'e', 'l', 'l', 'o' };
    ASCIIEncoding a = new ASCIIEncoding();
    byte[] bytes = a.GetBytes(chars);
    string s = a.GetString(bytes);
    Console.WriteLine(s);
    I thought there was an easier way too but I've forgotten myself.

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: System.Char[]

    How about:

    Code:
                char[] chars = { 'H', 'e', 'l', 'l', 'o' };
                MessageBox.Show (new string(chars));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width