src/Azos/Text/Utils.cs
/// <summary>
/// Returns a captured wildcard segment from string. Pattern uses '*' for match capture by default and may contain a single capture
/// </summary>
Returns a captured wildcard segment from string. Pattern uses '*' for match capture by default and may contain a single capture
Returns a captured wildcard segment from string . Pattern uses ' * ' for match capture by default and may contain a single capture
public static string CapturePatternMatch(this string str,     
                                                  string pattern,
                                                  char wc ='*',
                                                  StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
    {
       var i = pattern.IndexOf(wc);
       if (i<0) return string.Empty;
       var pleft = pattern.Substring(0, i);
       var pright = (i+1<pattern.Length)? pattern.Substring(i+1) : string.Empty;
       if (pleft.Length>0)
       {
         if (!str.StartsWith(pleft, comparisonType)) return string.Empty;
         str = str.Substring(pleft.Length);
       }
       if (pright.Length>0)
       {
         if (!str.EndsWith(pright, comparisonType)) return string.Empty;
         str = str.Substring(0, str.Length - pright.Length);
       }
       return str;
    }
public static string CapturePatternMatch ( this string str , string pattern , char wc = ' ' , StringComparison comparisonType = StringComparison . InvariantCultureIgnoreCase ) { var i = pattern . IndexOf ( wc ) ; if ( i < 0 ) return string . Empty ; var pleft = pattern . Substring ( 0 , i ) ; var pright = ( i + 1 < pattern . Length ) ? pattern . Substring ( i + 1 ) : string . Empty ; if ( pleft . Length > 0 ) { if ( ! str . StartsWith ( pleft , comparisonType ) ) return string . Empty ; str = str . Substring ( pleft . Length ) ; } if ( pright . Length > 0 ) { if ( ! str . EndsWith ( pright , comparisonType ) ) return string . Empty ; str = str . Substring ( 0 , str . Length - pright . Length ) ; } return str ; }
Returns a captured wildcard segment from string.
Returns a captured wildcard segment from string .
//     Pages/Dima/Welcome
string
this
pattern
string
wc
char
comparisonType
StringComparison