【发布时间】:2021-06-13 13:18:52
【问题描述】:
我在这里有一个示例段落:
var story = "Once upon a time, there was a little girl named <i>Goldilocks.</i>
She went for a walk in the forest. Pretty soon, she came upon a house. <strong>She
knocked and, when no one answered, </strong>she walked right in. At the table in the kitchen,
there were three bowls of porridge. Goldilocks was hungry. She tasted the porridge from the first bowl.";
我想要做的是在某些选定字符之前和之后修剪或删除某些段落。此特定段落位于</i> 之后和<strong> html 标记之前。到目前为止,我尝试使用Substring
story.Substring(story.IndexOf("<strong>"));
但它会删除 <strong> 之前的所有内容我想要达到的结果是这样的:
var story = "Once upon a time, there was a little girl named <i>Goldilocks.</i><strong>She
knocked and, when no one answered, </strong>she walked right in. At the table in the kitchen,
there were three bowls of porridge. Goldilocks was hungry. She tasted the porridge from the first bowl.";
没有She went for a walk in the forest. Pretty soon, she came upon a house.
我也试过了,
story = story.Substring(story.IndexOf("</i>")).Substring(0, story.LastIndexOf("<strong>" + 1);
但它不起作用。
有什么帮助吗?
【问题讨论】:
-
为什么要这样做?你的实际目标是什么?