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

Splitting on an asterisk using a regular expression

Is there a way to split a string by an asterisk using a regular expression in C#?
0
jeshbr
Asked:
jeshbr
  • 2
1 Solution
 
Expert1701Commented:
To use an asterisk in a regular expression, escape it with a backslash (the backslash, of course, needs to be escaped in c#, resulting in the code "\\*" or @"\*"):

  string input = "A*B*C";
  string[] output = System.Text.RegularExpressions.Regex.Split(input, "\\*");
  //output = string[] { "A", "B", "C" }

You can also use the String.Split method in this case:

  output = input.Split('*');
0
 
jeshbrAuthor Commented:
for some reason the Regex.Split does not work.

but the string.Split works fine.
0
 
jeshbrAuthor Commented:
thanks
0

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