Sharpen.Matcher.Group C# (CSharp) Method

Group() public method

public Group ( int n ) : string
n int
return string
        public string Group(int n)
        {
            if ((matches == null) || (current >= matches.Count)) {
                throw new InvalidOperationException ();
            }
            Group grp = matches[current].Groups[n];
            return grp.Success ? grp.Value : null;
        }

Usage Example

Example #1
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 private static Dispatch2 GetResultArray(bool matched, RegExpNI _this, Matcher m)
 {
     Dispatch2 array = TJS.CreateArrayObject();
     if (matched)
     {
         if (_this.RegEx == null)
         {
             Variant val = new Variant(string.Empty);
             array.PropSetByNum(Interface.MEMBERENSURE | Interface.IGNOREPROP, 0, val, array);
         }
         else
         {
             if (m != null)
             {
                 bool isMatch = m.Matches();
                 Variant val;
                 if (isMatch)
                 {
                     val = new Variant(m.Group(0));
                     array.PropSetByNum(Interface.MEMBERENSURE | Interface.IGNOREPROP, 0, val, array);
                 }
                 int size = m.GroupCount();
                 for (int i = 0; i < size; i++)
                 {
                     val = new Variant(m.Group(i + 1));
                     array.PropSetByNum(Interface.MEMBERENSURE | Interface.IGNOREPROP, i + 1, val, array
                         );
                 }
             }
         }
     }
     return array;
 }