gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:59:40 25 4
gpt4 key购买 nike

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

   [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

关于c# - 如何使用正则表达式删除特定字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31379074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com