欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C# 下划线转驼峰

程序员文章站 2022-06-01 07:49:53
...
/// <summary>
/// 转换
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
    string tb1 = textBox1.Text;
    Match mt = Regex.Match(tb1, @"_(\w*)*");
    while (mt.Success)
    {
        var item = mt.Value;
        while (item.IndexOf('_') >= 0)
        {
            string newUpper = item.Substring(item.IndexOf('_'), 2);
            item = item.Replace(newUpper, newUpper.Trim('_').ToUpper());
            tb1 = tb1.Replace(newUpper, newUpper.Trim('_').ToUpper());
        }
        mt = mt.NextMatch();
    }

    textBox2.Text = tb1;
}

C# 下划线转驼峰