-1

This program is a translator program that takes some symbols and converts them to normal letters. The problem is, when I try to put some symbols like: allAlphabets.Add("[]/[]"); or: allAlphabets.Add("//"); , i get an error about the UTF-16

        static void Main(string[] args)
        {
        string input = ""; // string input
        List<string> allAlphabets = new List<string>(); // storing to a list
        input = Console.ReadLine();
        char[] word = input.ToCharArray();
        for (int i = 0; i < word.Length; i++)
        {
            switch (word[i]) // switch casce
            {
           normal letters
                case 'm':
                    allAlphabets.Add("[]\/[]"); // represents text as a sequence of utf-16 code units 
                    break;
                case 'n':
                    allAlphabets.Add("[]\[]"); // represents text as a sequence of utf-16 code units
                case 'v':
                    allAlphabets.Add("\/"); // represents text as a sequence of utf-16 code units
                    break;
                case 'w':
                    allAlphabets.Add("\/\/"); // represents text as a sequence of utf-16 code units

             }
          }
       }
    }

Does someone know a way of encoding the unrecognized escape sequence? Thank you!

1 Answers1

4

You need to use the verbatim identifier (@)

To indicate that a string literal is to be interpreted verbatim. The @ character in this instance defines a verbatim string literal. Simple escape sequences (such as "\\" for a backslash), hexadecimal escape sequences (such as "\x0041" for an uppercase A), and Unicode escape sequences (such as "\u0041" for an uppercase A) are interpreted literally. Only a quote escape sequence ("") is not interpreted literally; it produces a single quotation mark. Additionally, in case of a verbatim interpolated string brace escape sequences ({{ and }}) are not interpreted literally; they produce single brace characters.

allAlphabets.Add(@"[]\/[]");

or escape the backslash

allAlphabets.Add("[]\\/[]")

Additional Resources

TheGeneral
  • 79,002
  • 9
  • 103
  • 141