A \"
in a string is not a backslash followed by a quote, but just a quote. The backslash in the string literal escapes the quote: it should be just a character, not the end of the string constant.
The \n
is not an escaped 'n' (it wouldn't need escaping) but a (single) newline character.
Your string literal doesn't really contain any backslashes.
Your code, with typos fixed:
var str = " \"AAP, FB, VOD, ART, BAG, CAT, DDL\"\n ";
int stIdx = str.IndexOf('"')+1; // output as 7 - you don't want position of " but 'A'
int edIdx = str.IndexOf('"', stIdx); // output as 39
Console.WriteLine($"from {stIdx} to {edIdx}"); // "from 7 to 39"
Console.WriteLine(str.Substring(stIdx, edIdx-stIdx)); // "AAP, FB, VOD, ART, BAG, CAT, DDL"
In a character literal (delimited by single quotes), you do not need to escape the double quote, so '"'
works fine. Although it is no problem if you do escape it: '\"'
- which is still a single "
character.