Sunday, 14 March 2010

Regular Expressions

Regular Expressions in C#

Not a general discussion of regular expressions nor a complete description of regexps in C#, just some notes incidental to learning how to use them in C#.

Example code might be found in csharp/regexp. Get NotAnt to build the code.

The code in here is directed toward the DotPlot program so it won't be a general discussion of regular expressions, search the net for that.

Microsoft's .NET framework documention suggests that the split method returns a string split into a list of tokens that includes the delimiters. If this really works and if it is practical to construct a single expression to express all of the delimiters then this will provide a perfect method of getting tokens for DotPlot. Look at the documentation for the Regex.Split method for details. Here is a qotation from it:

If capturing groups are used in a Regex.Split expression, the capturing groups are included in the resulting string array. The following example would yield the array items "one", "-", "two", "-", "banana".

  Regex r = new Regex("(-)"); // Split on hyphens.
  string[] s = r.Split("one-two-banana");

No comments:

Post a Comment

Blog Archive

Followers