本文整理汇总了C#中Matcher.Group方法的典型用法代码示例。如果您正苦于以下问题:C# Matcher.Group方法的具体用法?C# Matcher.Group怎么用?C# Matcher.Group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matcher
的用法示例。
在下文中一共展示了Matcher.Group方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: expand
/// <summary>
/// Similar to Python expand, return expansion where every \1, \2, etc. is
/// replaced by match.group(1), match.group(2), etc. Note: Even though this is
/// a general utility function, we define it locally because it is only tested
/// to work in the cases used by this class.
/// </summary>
///
/// <param name="match">The match object from String.match.</param>
/// <param name="expansion">The string with \1, \2, etc. to replace from match.</param>
/// <returns>The expanded string.</returns>
private static String expand(Matcher match, String expansion)
{
String result = "";
int beginIndex = 0;
Pattern regex = ILOG.J2CsMapping.Text.Pattern.Compile("\\\\(\\d)");
Matcher expansionMatcher = regex.Matcher(expansion);
while (expansionMatcher.Find()) {
result += expansion.Substring(beginIndex,(expansionMatcher.start())-(beginIndex));
result += match.Group(Int32.Parse(expansionMatcher.Group(1)));
beginIndex = expansionMatcher.end();
}
// Add the substring after the last match.
result += expansion.Substring(beginIndex,(expansion.Length)-(beginIndex));
return result;
}