Gambas-it

Gambas3 => Programmazione => Topic aperto da: vuott - 03 Aprile 2013, 10:41:11

Titolo: Effettuare una ricerca nelle stringhe usando espressioni regolari
Inserito da: vuott - 03 Aprile 2013, 10:41:11
Vorrei riportare questo messaggio apparso nella M.L.I.:

« I have often missed in Gambas the ability to search through strings
using a regular expression and provide a function to create replacements
Gambas doesn't have procedural pointers or closures, so it's
impossible to do it like in ruby/python/etc, but I've found the same
can be achieved using an iteratorin  the hope it is useful for others this is my module CRegex.

Here's an example, it turns the HTML tag """ into alternating
opening (``) and closing ('') quotes as required by the LaTeX system:


  
Codice: [Seleziona]
r = New CRegex(""", s, Regexp.Caseless)
   flag = False
   For Each r
      If flag Then
         flag = False
         r.Set("''") ' close quotes in LaTeX
      Else
         flag = True
         r.Set("``") ' open quotes
      Endif
   Next
   s = r.Subject


Ian Haywood »