Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在富文本编辑器中使用标签来指定数据字段。
例如 [开始] 和 [结束]
如何从包含标签的字符串块中删除 [Start] 和 [End] 之间的一段文本?
有没有比使用 IndexOf 和 Substring 等更简单的方法?
更新:我正在尝试使用 var output = Regex.Replace("[Start]SomeText[End]", @"(?<=[Start]).*(?=[End])", "")
但这种模式并不完全奏效。它需要删除 [Start] 和 [End] 之间的所有内容
考虑使用 Regex 替换 [Start] 和 [End] 之间的文本。以下代码片段应该会有所帮助...
var output = Regex.Replace("[Start]SomeText[End]", @"(?<=\[Start\]).*(?=\[End\])", "");
您可以使用正则表达式,但我想不出比在文件中搜索它更“简单”的方法。