如何替换一个string中的字节
如何替换一个string中每第五个字节 例如 把每第五个字节都换成X 输入“The Cat Sat on the Mat”, 输出是“The Xat SXt onXthe Xat”谢谢各位啦 --------------------编程问答-------------------- http://bbs.csdn.net/topics/390287270 --------------------编程问答-------------------- 循环string的每个字符,如果能被5整除,你就替换,一个个拼接 --------------------编程问答--------------------+1 --------------------编程问答-------------------- Regex reg = new Regex(@"(....)(.)");
string result = reg.Replace(yourStr, "$1X"); --------------------编程问答--------------------
string test = "The Cat Sat on the Mat";--------------------编程问答-------------------- 我是现学现卖哈哈哈 --------------------编程问答--------------------
Regex reg = new Regex(@"(?<=\G.{4}).");
string result = reg.Replace(test, "X");
@"(.)(.)"
--------------------编程问答--------------------
+1 --------------------编程问答--------------------
--------------------编程问答-------------------- 我是现学现卖哈哈哈 --------------------编程问答--------------------
static void Main(string[] args)
{
string a = "The Cat Sat on the Mat";
string b = "";
for (int i = 1; i < a.Length; i++)
{
if (i % 5 == 0)
{
b = b + "X";
}
else
{
b = b + a[i - 1];
}
}
Console.WriteLine(b);
Console.ReadKey();
}
--------------------编程问答-------------------- 7楼邪恶了....
string str="The Cat Sat on the Mat";
str = Regex.Replace(str, @"([\s\S]{4})[\s\S]", "$1X");
补充:.NET技术 , C#