如何使用正则表达式删除特定字符 - c#

我该如何解决?请不要介意数据注释的文本,这仅用于测试。我将如何删除数据注释?

   [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters",
        MessageId = "YouSource.DI.Web.Areas.HelpPage.TextSample.#ctor(System.String)",
        Justification = "End users may choose to merge this string with existing localized resources.")]
    [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly",
        MessageId = "bsonspec",
        Justification = "Part of a URI.")]
    public int Get1Number([FromBody]string name)

我有这个代码

    public void RemovePublicModifier()
    {
        this.method = this.SanitizeString(this.method, Public);
    }
    public void RemoveDataAnnotation()
    {
        int startIndex = this.method.LastIndexOf(']');
        var result = this.method.Substring(startIndex + 1).Trim();

        this.method = result;
    }
    private string SanitizeString(string method, string filter)
    {
        var items = method.Split(' ').ToList();
        var publicItem = items.Where(i => i == filter).FirstOrDefault();
        if (publicItem != null)
        {
            items.Remove(publicItem);
        }
        var result = string.Join(" ", items.ToArray()).Trim();
        return result;
    }

但这给我一个错误的结果。

       string name)

我想要的是。

      int Get1Number([FromBody]string name)

参考方案

string inputStr = @"[SuppressMessage(""Microsoft.Globalization"", ""CA1303:Do not pass literals as localized parameters"",
MessageId = ""YouSource.DI.Web.Areas.HelpPage.TextSample.#ctor(System.String)"",
Justification = ""End users may choose to merge this string with existing localized resources."")]
[SuppressMessage(""Microsoft.Naming"", ""CA2204:Literals should be spelled correctly"",
MessageId = ""bsonspec"",
Justification = ""Part of a URI."")]
public int Get1Number([FromBody]string name)";
Console.WriteLine(Regex.Replace(inputStr, @"(^|\s*)\[[\s\S]*?\]\s*public\s+", string.Empty));

public is also removed

当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java

我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

改造正在返回一个空的响应主体 - java

我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…

用大写字母拆分字符串,但忽略AAA Python Regex - python

我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…

java split regex-字符的任意组合 - java

我正在使用3个字符分割字符串:空格,破折号和逗号我想要的是能够使用这3个字符的任意组合进行拆分,例如:-,(破折号后跟逗号)或,--(逗号后加2破折号)或- , -(破折号,逗号间隔破折号)等 String address = "Sector -18B, Dwarka"; String[] addressParts = address.s…

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …