Search code examples
c#asciiirc

How can I turn on special Ascii characters in Visual Studio?


Or more specifically. The Ascii control character. ^C, 0x03, or STX. I am trying to get my program to send out color codes in IRC ( I know there is not really a standard for this ), but I am a atleast an hour into research, and I don't know what else to search for. And I don't see anything in VS 2010's options.

Link to ascii reference.

All I need to get VS to stop being dumb, and let me input into the text editor the STX or ETX characters. I did already try the encoding in the save as. Any thoughts or ideas please?


Solution

  • You can encode any character using escape sequences:

    string s = "\x03"; // note: hexadecimal value
    

    While it is technically possible to get at least some special characters directly in a string, it will be completely hopeless to make sense of since they can't be displayed properly.

    Full list (swiped from this page):

    \' - single quote, needed for character literals
    \" - double quote, needed for string literals
    \\ - backslash
    \0 - Unicode character 0
    \a - Alert (character 7)
    \b - Backspace (character 8)
    \f - Form feed (character 12)
    \n - New line (character 10)
    \r - Carriage return (character 13)
    \t - Horizontal tab (character 9)
    \v - Vertical quote (character 11)
    \uxxxx       - Unicode escape sequence for character with hex value xxxx
    \xn[n][n][n] - Unicode escape sequence for character with hex
                   value nnnn (variable length version of \uxxxx)
    \Uxxxxxxxx   - Unicode escape sequence for character with hex
                   value xxxxxxxx (for generating surrogates)