【发布时间】:2012-04-18 01:41:31
【问题描述】:
我想知道是否有任何方法可以替换字符串中的子字符串,但可以在字符串之间交替替换它们。即,匹配所有出现的字符串"**",并将第一个出现替换为"<strong>",将下一个出现替换为"</strong>"(然后重复该模式)。
输入将是这样的:"This is a sentence with **multiple** strong tags which will be **strong** upon output"
返回的输出是:"This is a sentence with <strong>multiple</strong> strong tags which will be <strong>strong</strong> upon output"
【问题讨论】:
-
您可以在循环中使用带有起始索引的
IndexOf。 -
@CodeInChaos 我并没有真正经常使用IndexOf,会看看它,但你有什么实现方法吗?
标签: c# string substring markdown