Non-encoded control characters and whitespace characters are often injected in the source code because of a bad manipulation. They are either invisible or difficult to recognize, which can result in bugs when the string is not what the developer expects. If you actually need to use a control character use their encoded version:
This rule raises an issue when the following characters are seen in a string literal:
U+200B, U+200C, U+200D, U+2060, U+FEFF, U+2028, U+2029 U+0020, ASCII 32 string tabInside = "A B"; // Noncompliant: contains a tabulation string zeroWidthSpaceInside = "foobar"; // Noncompliant: contains a U+200B character inside Console.WriteLine(zeroWidthSpaceInside); // Prints "foo?bar"
string tabInside = "A\tB"; // Compliant: escaped value string zeroWidthSpaceInside = "foo\u200Bbar"; // Compliant: escaped value Console.WriteLine(zeroWidthSpaceInside); // Prints "foo?bar"