Grasshopper

algorithmic modeling for Rhino

I'm working with l-systems and would like to know if it is possible to access regular expressions in vb.net components, like in the following example:

Dim StringToCheck As String = "EEOOAA"
Dim StringToFind As String = "A"
Dim exp As New Regex(StringToFind, RegexOptions.IgnoreCase)
Dim Occurrences As Integer = exp.Matches(StringToCheck).Count

This returns an error that Regex is not defined, but i cannot import, else i suppose i would just include the following:

Imports System.Text.RegularExpressions

I know my problem can be solved in other ways, but in the long run regular expressions could come in handy. Is there any way to access them?

/Thomas

Views: 1304

Replies to This Discussion

Hi Thomas, a good way is to use the standard namespaced class definition:

Dim StringToCheck As String = "EEOOAA"
Dim StringToFind As String = "A"
Dim exp As New System.Text.RegularExpressions.Regex (StringToFind, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim Occurrences As Integer = exp.Matches(StringToCheck).Count
A = Occurrences


Now you can harness regular expressions fully. Btw, to take advantage of the Regex cache, use the static methods of the Regex class: e.g. System.Text.RegularExpressions.Regex.Replace() (see static signatures here) and read a discussion here: "The 2.0 Regex class no longer caches parsed regular expressions created by Regex instance methods, it only caches regular expressions created by Regex static methods".

Hope this helps,
Giulio
Super!!

Thanks Giulio, i'm gonna test it right away

/Thomas

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service