How to subtract two strings in c#

Introduction

Subtract integer, decimal values are too much easy using C# programing language, but when someone asks to subtract two strings, That time we get some confusion. We just think about how we will subtract two strings in c#. Let’s accomplish it.

Subtract two strings in c#

For making this possible, I will create a console application using C#. I will take 3 strings as variables, from those I will take 2 strings as input field. In the 3rd variable, I will store the result.
 
Below code is the solution for how to subtract two strings in c#.net
static void Main(string[] args)
        {
            string str1 = "Bidya";
            string str2 = "Bidya Sagar Mishra";
            string str3= str2.Replace(str1, "");
            Console.WriteLine(str3);
        }
  • Here str1 and str2 contain two different string values.
  • Subtracted, both the strings.
  • Stored the result in str3.

SUMMARY

In the above article, I explained how we can subtract two strings. If you find helpful information from this article, please share it with your colleagues and the development community. Happy to help you 😊.

1 thought on “How to subtract two strings in c#”

Leave a Comment

Your email address will not be published. Required fields are marked *