home
links
tips

code
users
tools
tutorials
projects
web
help
design

mudabone
suletzki
trans48
nutrition reality

MarthaAttire!

code Reg X


using System;
using System.Text.RegularExpressions;

namespace regX
{
     /// <summary>
     /// Summary description for regx.
     /// </summary>
     public class regx
     {
          public regx()
          {
          }

          public string[] split(string sData, string sToken)
          {
               Regex r = new Regex("(" + sToken + ")");
               string[] s = r.Split(sData);

               int iHalf = System.Convert.ToInt16((s.GetUpperBound(0) / 2) + 1);
               string[] res = new string[iHalf];

               int j = 0;
               for (int i=0; i <= s.GetUpperBound(0); i++)
               {
                    if (s[i] != sToken)
                    {
                         res[j] = s[i];
                         j++;
                    }
               }
               return res;
          }

          public string removeScriptTags(string sHTML)
          {
               return this.regExReplace("<SCRIPT[^>]*>[^v]*?</SCRIPT>","",sHTML);
          }

          public string regExReplace(string sRegEx, string sReplacement, string sData)
          {
               Regex r = new Regex(sRegEx, RegexOptions.Multiline | RegexOptions.IgnoreCase);
               string res = r.Replace(sData,sReplacement);
               return res;
          }

          public string findFirstSubMatch(string sData, string sRegX)
          {

               string res = "";

               try
               {
                    Regex r = new Regex(sRegX);
                    System.Text.RegularExpressions.Match m = r.Match(sData);
                    res = m.Groups[1].Captures[0].ToString();
               }
               catch (System.ArgumentOutOfRangeException)
               {
                    res = "";  //no first match
               }
               catch (System.Exception e)
               {
                    res = e.Message;
               }
               finally
               {
               }

               return res;
          }

          private void debugPrint(string s)
          {
               System.Diagnostics.Debug.WriteLine(s);
          }

     }
}


Last Modified 10/2/03 1:31 PM

Hide Tools