Deleted words from a string

Use String.Replace():

string x = @"documents\bin\debug";
string desiredString = x.Replace(@"\bin\debug", String.Empty);

Note: The key thing here is that you have to assign the string returned by the Replace() function to a variable. (From your comment on the question, it is the problem). This can either be another variable (as in the above example) or the same variable:

string x = x.Replace(@"\bin\debug", String.Empty);

Implicitly, not assigning the return value to a variable (or using the former way) will keep the value of x, unchanged, which is the exact problem you’re facing. Hope it helps 🙂

Leave a Comment