C#删除bounderies内的字符串

问题描述 投票:2回答:1

对不起,如果这是重复的或什么,但我无法找到解决方案在c#我的问题。我有c# string 看起来像这样。

string aa = "First Example (first to delete) , Second example ( Second to delete ) , Thrird Example ( Third to delete )"

我想从这个字符串中删除所有在里面的东西 ( SOME INPUT )().

问题是,我不知道这是什么 SOME INPUT 是。我只知道它在里面 ().

谢谢你的帮助。

c# string c#-4.0 string-matching
1个回答
3
投票

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);
    }
}

输出。第一个例子,第二个例子,第三个例子

© www.soinside.com 2019 - 2024. All rights reserved.