从指定的loaction替换string的文本 [英] replace text of string from specified loaction
本文介绍了从指定的loaction替换string的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串aaaabbbbccccddddaaaabbbbccccdddaabbbbbccccdddd。
i想要覆盖aaaa到dddd,但只根据情况从一个地方覆盖。
所以我想设置偏移直到长度。并覆盖数据。
谢谢
i have an string aaaabbbbccccddddaaaabbbbccccddddaaaabbbbccccdddd.
i want to overwrite aaaa to dddd but from only one wherever want according to situation.
so i want to set offset till the length. and overwrite the data.
thanks
推荐答案
正则表达式和@Snehasish_Nandy的提议可行:
A combination of regular expressions and @Snehasish_Nandy 's proposal would work:
string pattern = "aaaabbbbccccdddd";
string replacement = "eeffgghh";
int whichOne = 3;
System.Text.RegularExpressions.MatchCollection matches = System.Text.RegularExpressions.Regex.Matches(input, pattern);
if (matches.Count >= whichOne)
{
StringBuilder sb = new StringBuilder(input);
sb.Remove(matches[whichOne].Index, matches[whichOne].Length);
sb.Insert(matches[whichOne].Index, replacement);
string output = sb.ToString();
}
使用IndexOf,SubString,替换函数来执行你的任务..
评论您的实际要求。获得确切的解决方案。
use IndexOf , SubString , Replace functions to perform ur task..
comment ur actual requirement. to get the exact solution.
为此使用String.Substring函数
use "String.Substring" function for this
这篇关于从指定的loaction替换string的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文