Hi Guys
Need help to understand given query what exactly doing here
Hi,
This expression compares ddMMyy style current time string with ddMMyy style datetime string which is converted from dumpdatetime which is CST to IST.
However, I think this is not very good, because ddMMyy style string is not always in order of the timeline in string comparison. (For example, “021122” is less than “311022” in string comparison.)
Regards,
So what is return as i have seen here <=
And can you please tell me the best way appreciate
Hi,
First of all, can you check the following document. This document says if return value equals zero, two string is same. If return value is negative, The instance (now.ToString(“ddMMyy”)) precedes the argument (IST based dumpdatetime). If positive, the instance follows the argument.
So, perhaps you should replace “ddMMyy” with “yyMMdd”. However please note that it depends requirement of your process.
Regards,
using System;
public class Example
{
public static void Main()
{
string strFirst = “Goodbye”;
string strSecond = “Hello”;
string strThird = “a small string”;
string strFourth = “goodbye”;
// Compare a string to itself.
Console.WriteLine(CompareStrings(strFirst, strFirst));
Console.WriteLine(CompareStrings(strFirst, strSecond));
Console.WriteLine(CompareStrings(strFirst, strThird));
// Compare a string to another string that varies only by case.
Console.WriteLine(CompareStrings(strFirst, strFourth));
Console.WriteLine(CompareStrings(strFourth, strFirst));
}
private static string CompareStrings( string str1, string str2 )
{
// Compare the values, using the CompareTo method on the first string.
int cmpVal = str1.CompareTo(str2);
if (cmpVal == 0) // The strings are the same.
return "The strings occur in the same position in the sort order.";
else if (cmpVal < 0)
return "The first string precedes the second in the sort order.";
else
return "The first string follows the second in the sort order.";
}
}
// The example displays the following output:
// The strings occur in the same position in the sort order.
// The first string precedes the second in the sort order.
// The first string follows the second in the sort order.
// The first string follows the second in the sort order.
// The first string precedes the second in the sort order.
I have doubt in last 4 and 5 out put if we are passing the same string why result is defer ?
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.