using System.Text.RegularExpressions;

class RegExSample 
{
   
static string CapText(Match m) 
   {
      
// Get the matched string.
      string x = m.ToString();
      
// If the first char is lower case...
      if (char.IsLower(x[0])) 
      {
         
// Capitalize it.
         return char.ToUpper(x[0]) + x.Substring(1, x.Length-1);
      }
      
return x;
   }
    
   
static void Main() 
   {
      
string text = "four score and seven years ago";
      System.Console.WriteLine(
"text=[" + text + "]");
      
string result = Regex.Replace(text, @"\w+",
         
new MatchEvaluator(RegExSample.CapText));
      System.Console.WriteLine(
"result=[" + result + "]");
   }
}

相关文章:

  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2021-11-21
  • 2021-11-02
猜你喜欢
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案