Autore Topic: Effettuare una ricerca nelle stringhe usando espressioni regolari  (Letto 297 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.334
  • Ne mors quidem nos iunget
    • Mostra profilo
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 »
« Ultima modifica: 03 Aprile 2013, 10:44:05 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »