ganjan
ganjan

Reputation: 7596

How to express the ' character as a character literal

So I want an array of char object similar to this:

        char[] allowedCharactersUnreserved = new char[] {
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_', '.' 
        };

Problem is saving the: ' element

        char[] allowedCharactersReserved = new char[] {
           '#', '[', ']', ''' <---- problem
        };

I get an "empty character literal" error

Upvotes: 1

Views: 6804

Answers (3)

S3ddi9
S3ddi9

Reputation: 2151

its better to use

char[] allowedCharactersUnreserved = 
       @"ABCDEFGHIJKLMNOPQRSTUVWXYZabc'[]""#".ToCharArray(); //where ("") char is (")

Upvotes: 2

Douglas
Douglas

Reputation: 54897

You need to escape it using a backslash: '\''. It's the same as you would do to escape " in a string: "\"".

Upvotes: 2

Stelian Matei
Stelian Matei

Reputation: 11623

Try to escape the ' character with the \ character: '\''

Upvotes: 12

Related Questions