简体   繁体   中英

C# Remove the escape character

I've came across a problem with creating Facebook campaigns from .net code. The campaign name has a limit of 100 characters. When I try to submit a name that is exactly 100 chars long but with a double quote like:

var name = "avery\"ongnamewithalotoflettersandcharacterswhoknowswhyaverylongnamewithalotoflettersandcharacterswho";

.net counts the string length as 100 but FB as 101, counting the \\ as extra character and fails the validation.

Wonder if there is a way to remove the \\ before submission to FB?

If I split the string into code array @ http://jdstiles.com/java/cct.html

it shows code 92 for the escape slash but I'm unable to do the same in C#

Any ideas?

For string in .NET, \\ and " are not separate characters. \\" is an escape sequences and it counts as one character.

As far as I aware, that's not possible.

You can't use " in your string without \\ except verbatim string literal . Even if you delete your \\ in your string, as far as I know, there is no way to change your string from regular string literal to verbatim string literal .

Try:

var name = @"c:\all\Special\Chars\Are\Escaped";

or

Insert the char in manually

var name = "firstPart" + char(90) + "secondPart";

Maybe the FB counts the termination \\0 as the additional character. Then you can effectively have only 99 visible characters and nothing you can do about it, sorry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM