// 输入 tring 类型 ,数据是 AaaaBbbb 
// 返回 tring , AAAA_BBBB
//
// 但遇到字母大写的时候就插入下划线,
// 返回的都是大写字母,输入的数据不存在数字。
// 全部是英文字母
//
//
// public string GetTableName(string modelName)
// {
// ...
// }
//
//
// 例子:
// AaaBbbCcc => AAA_BBB_CCC
//
//
// AaaBCD => AAA_B_C_D

解决方案 »

  1.   

    static string CapText(Match m) 
    {
    // Get the matched string.
    string x = m.ToString();
    return "_" + x;
    }
        
    static void Main() 
    {
    string text = "AadfaADFasddfaDFAdfadAddf";
    System.Console.WriteLine("text=[" + text + "]");
    string result = Regex.Replace(text, @"[A-Z]",
    new MatchEvaluator(RegExSample.CapText));
    System.Console.WriteLine("result=[" + result + "]");
    }
      

  2.   

    using System.Text.RegularExpressions;class RegExSample 
    {
    static string CapText(Match m) 
    {
    // Get the matched string.
    string x = m.ToString();
    return "_" + x;
    }
        
    static void Main() 
    {
    string text = "AadfaADFasddfaDFAdfadAddf";
    System.Console.WriteLine("text=[" + text + "]");
    string result = Regex.Replace(text, @"[A-Z]",
    new MatchEvaluator(RegExSample.CapText));
    System.Console.WriteLine("result=[" + result + "]");
    }
    }
    上面那个没类名,可能编译不过