• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 799
  • Last Modified:

Split with character \

I've just started working with C#.

I'm trying to split a string into an array at the point where the string has a slash character \  

But it seems to be a special little slash to C# because if I try to use this line

string[] arrUsername = RemoteUser.ToString().Split(("\").ToCharArray());

The text after the character turns a different color and VS tells me I'm starting a new line there ("new line in constant").

My attempts to code it alternatively as ASCII character 92 are met with "  'char' is a type but is used like a 'variable'   ", which I don't understand (background is VB.NET)

Is there another way I could code this line ?


Christian



(Here's the definition of RemoteUser, a local string I'm trying to split in that line)
 
string RemoteUser = Request.ServerVariables["REMOTE_USER"];
0
CAWhite
Asked:
CAWhite
  • 2
1 Solution
 
Fernando SotoRetiredCommented:
Hi CAWhite;

In C# the \ in a string is an escape character. To have the compiler to ignore it in a string use the @ sign as below.

string[] arrUsername = RemoteUser.ToString().Split((@"\").ToCharArray());

Fernando

0
 
CAWhiteAuthor Commented:
Thanks !
0
 
Fernando SotoRetiredCommented:
Not a problem, glad to help. ;=)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now