简体   繁体   中英

Remove a section of text from string c#

I'm using tags in a richtexteditor to specify data fields.

Eg [Start] and [End]

How can I remove a section of text between [Start] and [End] from a string block including the tags?

Is there an easier way rather than using IndexOf and Substring etc?

Update: I'm attempting to use var output = Regex.Replace("[Start]SomeText[End]", @"(?<=[Start]).*(?=[End])", "")

But the pattern does not quite work. It needs to remove everthing between [Start] and [End]

Consider using Regex to replace the text between [Start] and [End]. The following code snippet should help...

var output = Regex.Replace("[Start]SomeText[End]", @"(?<=\[Start\]).*(?=\[End\])", "");

你可以使用正则表达式,但我想不出比搜索文件更容易的东西。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM