繁体   English   中英

如何替换整个文本中两个字符之间的字符串?

[英]How to replace string between two characters in whole text?

我有以下字符串:

{Name}({Age})

我想得到以下内容:

()

我试过这个代码:

@"\{([^\}]+)\}" Only return {Name}

"({)(.*)(})" Return {Name}({Age}

但是他们都没有像我想要的那样工作。

这该怎么做?

这应该这样做:

class Program
{
    static void Main(string[] args)
    {
        string input = @"{Name}({Age})";

        string output = Regex.Replace(input, @"\{.*?\}", "");

        Console.WriteLine(output); // "()"
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM