string
-
How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.
-
How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.
simworld wrote:
Is there any system defined function such as strcmp,strcpy as used in C
To compare 2 strings, you could use the String.Compare method. To copy one string value into another, all you do is
string oldValue = "OldValue"; string newValue = oldValue;
-
How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.
-
How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.
There are several ways you can compare strings in C#. The simplest way is to just test using equality:
string a = "This is a test";
string b = "This is another test";if (a == b) {
// do something
}However, this will do a case-sensistive, culture-sensitive compare which may not be what you want and isn't necessarily the most performant test. The closest methods to strcmp in C# are going to be the
String.Compare
,String.CompareOrdinal
or theString.CompareTo
methods. In order to copy a string, you can simply copy it. Strings in C# are immutable, so you will always get a new instance of the string:string a = "This is a test";
string b = a;You can find all of the string methods here[^].
Scott. —In just two days, tomorrow will be yesterday. —Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[Forum Guidelines] [Articles] [Blog]
-
How to Compare two Stringsand to copy string into other string using C# Code. What is the syntax? Is there any system defined function such as strcmp,strcpy as used in C I am taken two values in strings , now I want to compare which one is greater. I can do it treating values as int or to convert.ToInt32, but requirement is to treat and compare them as strings.