【发布时间】:2009-10-15 16:10:17
【问题描述】:
我想在 .NET 应用程序中就地获取和编辑字符串。我知道StringBuilder 允许我进行就地追加、插入和替换,但它不允许像这样简单的方法:
while (script.IndexOf("@Unique", StringComparison.InvariantCultureIgnoreCase) != -1)
{
int Location = script.IndexOf("@Unique", StringComparison.InvariantCultureIgnoreCase);
script = script.Remove(Location, 7);
script = script.Insert(Location, Guid.NewGuid().ToString());
}
因为StringBuilder 中没有IndexOf。有没有人有一种有效的方法来对文本信息进行就地编辑?
编辑#1: 更改示例以更明显地表明每个“替换”都需要有不同的结果。
【问题讨论】: