Split string using backslash

It's backslash, a character literal.

To do the split:

String[] breakApart = sentence.Split('\\');

Try using the escaped character '\\' instead of '\':

String[] breakApart = sentence.Split('\\');

The backslash \ in C# is used as an escape character for special characters like quotes and apostrophes. So when you are trying to wrap the backslash with apostrophes, the backslash together with the final apostrophe is being interpreted as an escaped apostrophe.

Here is a list of character escapes available in C#.

Here is Microsoft's documentation for character literals in C#.

Tags:

C#

String

Split