C# Tutorials and offshore development in India
Tutorials Resources Forum Reviews Communities Interview Jobs Projects Training Your Ad Here


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

String functions vb.net (Urgent)


Posted Date: 15 Mar 2005      Posted By: Syed Sayeeduddin Hussaini      Member Level: Silver     Points: 2   Responses: 3



Hi,

I want to compare multiple strings, I am having 4 strings and I want to compare them for duplication i.e; no two string will be similar.

One method we can do it by using if statement.

if str1=str2 and str2=str3 and str3=str1 ..... then
......

end if.

Or

we can do it by using the nested if statement .

But I want to do by using a function which will compare all the 4 strings and give the result.

Please help me.... (Urgent)

Regards,
Sayeed.





Responses

Author: Sandip Naskar    15 Mar 2005Member Level: GoldRating: 2 out of 52 out of 5     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 2005Member Level: SilverRating: 2 out of 52 out of 5     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 2005Member Level: BronzeRating: 2 out of 52 out of 5     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



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Previous : Validation Controls
Return to Discussion Forum
Post New Message
Category: ASP.NET




About Us    Contact Us    Privacy Policy    Terms Of Use