Top community members
All Wiki Articles Create Wiki Article

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

C# / .NET - string replace

0 contributions
1 points

In C# / .NET it is possible to replace part of string in few ways.

1. String.Replace method example

string input = "My name is John.";
string output = input.Replace("John", "Kate");

Console.WriteLine(output);

Output:

My name is Kate.

2. Regex.Replace instance method example

Regex regex = new Regex("John");

string input = "My name is John.";
string output = regex.Replace(input, "Kate");

Console.WriteLine(output);

Output:

My name is Kate.

3. Regex.Replace static method example

string pattern = "John";

string input = "My name is John.";
string output = Regex.Replace(input, pattern, "Kate");

Console.WriteLine(output);

Output:

My name is Kate.

4. References

  1. String.Replace Method - Microsoft Docs
  2. Regex.Replace Instance Method - Microsoft Docs
  3. Regex.Replace Static Method - Microsoft Docs
0 contributions

Suggested wiki articles:

Suggested findings

Let's do the work and have some fun
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way. ❤ 💻 🙂
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    we will help you. 👍 ✔ 🦄
Read more