randy newfield
randy newfield

Reputation: 1221

string literals/escapes

I am wondering if there is some sort of string prefix so that the cstring is taken as is without the need of my escaping all the characters. I am not 100% sure. I remember something about prefixing the string with the @ symbol ( char str[] = @"some\text\here"; ) and you would not need to escape any of your characters such as \, \n,.etc. im working with curl and urls and it is a pain to have to escape every single backslash.

can anyone spread some light on this or am i stuck escaping every character prefixed with a backslash?

Upvotes: 1

Views: 124

Answers (3)

exexzian
exexzian

Reputation: 7890

This feature is not available in C. It seems you read about verbatim string literals of C#

and if you have to escape - escape characters in C you need to escape that using backslash ( \ )

Upvotes: 1

SecurityMatt
SecurityMatt

Reputation: 6743

No. In C there are only two types of "string", the string literal surrounded by double quotes and the char literal surrounded by single quotes.

In both cases you must backslash escape characters that have special meaning.

Upvotes: 2

Bart Friederichs
Bart Friederichs

Reputation: 33511

In C, there is no such thing. You are stuck escaping everything, or perhaps you could put your URLs in a file and read them in.

Upvotes: 1

Related Questions