| Author: Sandip Naskar 15 Mar 2005 | Member Level: Gold | Rating:  Points: 2 |
Hi,
By using string.Compare and string.CompareOrdinal, you can check 2 string values. So, practically by using string function will not solve your purpose.
You have to write a function to get what you want.
Here is the 2 overloaded methods Ist method is simple expects 4 string values as argument 2nd method is little bit complex. You can compare any no. of strings by passing all the strings as array of string.
private int CompareAll(string str1, string str2, string str3, string str4) { if(str1==str2 && str2==str3 && str3==str4) { return 0; } else { return 1; } }
private int CompareAll(string[] Values) { string strTemp=""; foreach(string str in Values) { if(strTemp=="") { strTemp=str; } else { if(str!=strTemp) return 1; strTemp=str; } } return 0; }
The code is in C#. If you want it in VB.NET, please let me know.
Thank you, Sandip
|
| Author: Syed Sayeeduddin Hussaini 15 Mar 2005 | Member Level: Silver | Rating:  Points: 2 |
Hi Sandip,
I am using vb.net, I had converted your first function into vb.net.
Your code is working fine, But I want to avoid the duplication. U R function is not avoiding duplication i.e; All the 4 strings must be different.
Please help me...
Thanks & Regards, Sayeed.
|
| Author: Ravi 16 Mar 2005 | Member Level: Bronze | Rating:  Points: 2 |
Hi I can give you logic but I am not sure about syntax
private int CompareAll(string str1, string str2, string str3, string str4) { dim strArray = new Array{str1, str2, str3, str4) dim str as string; str = strArray(0) for (var i=1;i<=3;i++) { for (var j=i+1;j<=4;j++) { if (str == strArray(j)) { return 0; } } str = strArray(i+1) } return 1; } This should work
|