C# replace 方法
作者:
波波有理的菠菜 | 来源:发表于
2021-09-30 10:50 被阅读0次 string keyword = "内链1";
string content1 = "这是一篇内链1内容内链1";
int start = content1.IndexOf(keyword);
int length = keyword.Length;
StringBuilder contentBuilder = new StringBuilder(content1);
//这里的Replace方法,可以传入开始和替换指定长度,与String.Replace稍有不同,可以确保一个内链只出现一次
contentBuilder.Replace(keyword, $@"<a href=""#"">{keyword}</a>", start, length);
string newContent = contentBuilder.ToString();
本文标题:C# replace 方法
本文链接:https://www.haomeiwen.com/subject/bbcenltx.html
网友评论