对不起,如果这是重复的或什么,但我无法找到解决方案在c#我的问题。我有c# string
看起来像这样。
string aa = "First Example (first to delete) , Second example ( Second to delete ) , Thrird Example ( Third to delete )"
我想从这个字符串中删除所有在里面的东西 ( SOME INPUT )
与 (
和 )
.
问题是,我不知道这是什么 SOME INPUT
是。我只知道它在里面 ()
.
谢谢你的帮助。
https:/dotnetfiddle.netJnhszs等。
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
var text = "First Example (first to delete) , Second example ( Second to delete ) , Thrird Example ( Third to delete )";
text = Regex.Replace(text, @"\([^)]*\)", "");
text = Regex.Replace(text, @"\s{2,}", " ");
Console.WriteLine(text);
}
}
输出。第一个例子,第二个例子,第三个例子