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

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

how to make the result ", no, Wow"

  • 5
    Step First: Copy your Title into your Google Searchbar. Step Two: Press Enter. Step Three: Look at results. Step Four: Delete this question from SO. – Smartis has left SO again Feb 07 '16 at 14:29
  • 3
    Possible duplicate of [How do I replace the \*first instance\* of a string in .NET?](http://stackoverflow.com/questions/141045/how-do-i-replace-the-first-instance-of-a-string-in-net) – Smartis has left SO again Feb 07 '16 at 14:45
  • do you only want to remove the word if it is the first word, or do you want to remove the first instance of the word. Basically what of the string was "this is a Wow moment, really Wow" – juharr Feb 07 '16 at 15:02

2 Answers2

1

As the two other guys giving an answer didn't look in the title (He says first word, not "Wow"), you can do it like this (But please google it for future quest first, before you post it here):

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

myfather = myfather.Substring(x);
91378246
  • 488
  • 6
  • 14
0

Like suggested before, but without the need to define anything else:

string myfather = "Wow, no, Wow";
myfather=myfather.Remove(0, "Wow".Length);
Twilight
  • 31
  • 4
  • What is the difference from @Felix answer? – Guy Feb 07 '16 at 14:38
  • @guy this is, in fact, "a little" more efficient, however, the difference is basically meaningless – Camilo Terevinto Feb 07 '16 at 14:40
  • @cFrozenDeath Because he didn't define `string textToReplace = "Wow";`? He saved one line of code in the price of hard code (as oppose to generic code). I don't see it as more efficient. – Guy Feb 07 '16 at 14:54
  • @guy not only the assignment, but on the string search, this already knows that the removal should start at 0, the other could start anywhere, which is not the point. – Camilo Terevinto Feb 07 '16 at 14:56