C#如何替换字符串

时间:2016-02-07 14:21:10

标签: c# string replace

string myfather = "Wow, no, Wow";
myfather = myfather.Replace("Wow", "");

//how to make the result ", no, Wow" 
  

如何制作结果“,不,哇”

2 个答案:

答案 0 :(得分:1)

由于另外两个给出答案的人没有看到标题(他说第一个字,而不是" Wow"),你可以这样做(但请先将谷歌搜索为未来的任务,然后再将其发布到此处):

string myfather = "Wow, no, Wow";
int x = 0;
foreach (char c in myfather)
   if (c == ',' || c == ' ')
       break;
   else
       x++;

myfather = myfather.Substring(x);

答案 1 :(得分:0)

像之前建议的那样,但不需要定义任何其他内容:

string myfather = "Wow, no, Wow";
myfather=myfather.Remove(0, "Wow".Length);