思想:修改字符串中某一个字符串首先将字符串提取成一个字符数组,然后找到修改的字符串,判断与要修改的字符串是否相等
如相等则利用字符数组不断的加加来修改,最后重新还原成一个字符串数组
using System;
using System.Collections.Generic;
using System.Text;
namespace Lesson2
{
class ModiFyString
{
static void Main()
{
string s = "www.peilong@163.com";
Console.WriteLine("修改前的内容是"+s);
//将字符串提取到char数组中
char[] chars = s.ToCharArray();
int index = s.IndexOf("peilong");
if(index!=-1)
{
chars[index++] = 'h';
chars[index++] = 'e';
chars[index++] = 'l';
chars[index++] = 'l';
chars[index++] = 'o';
}
s = new string(chars);
Console.WriteLine("修改后的字符串是:{0}", s);
}
}
}