c# - 从 C# 中的一行中删除子字符串 "dynamically"

标签 c# string

我有一个像这样的文本文件中包含一些行的文件

This is a test value with {MyTestValue = 0.34} How do I delete the test value? My line also has {MySecondTestValue = 0.35}

MyTestValue 的值在每一行中不是相同的值。

有没有办法确定直到右括号的字符数并删除括号内的所有内容。所以我的输出会是这样的:

This is a test value with {}  How do I delete the test value? My line also has {MySecondTestValue = 0.35}

最佳答案

可能通过正则表达式实现:

String source = "This is a test value with {MyTestValue = 0.34} How do I delete the test value?";

String result = Regex.Replace(source, "{.*}", (MatchEvaluator) ((match) => "{}"));

关于c# - 从 C# 中的一行中删除子字符串 "dynamically",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31426177/

相关文章:

c# - LINQ 中多个实例的相等比较/IEqualityComparer 问题

python - 使用 str(count) 追加到列表会出错

c# - FindVisualChild引用问题

c# - 如何在仍然使用 ASP.NET MVC 的同时为网站开发快速原型(prototype)?

c# - 在图像按钮上滚动页面 Div 也向下滚动

Javascript正则表达式查找字符串并从整个字符串中提取它

c++ - 无法将参数 'std::basic_string<char>' 的 'const char*' 转换为 '1' 到 'int system(const char*)'

java - Java中删除字符串

java - 将只读字符串插入 jTextArea

c# - 将 TextWriter 与 StreamWriter 一起使用并同时读取/写入