Hi,

You can write program for Comparing string in C# without using
String.Compare() function.

bool CompareString(string source, string dest)

{

if(source.Length != dest.Length)

return false;

int sourceLen = source.Length;

for(int iCounter = 0; iCounter < sourceLen; iCounter++)

{

if(source.Substring( iCounter, 1) != dest.Substring( iCounter, 1))

return false;

}

return true;
}

Hope this code will help you.

Regards,
Praveen

On Fri, Dec 12, 2008 at 2:08 AM, [email protected]
<[email protected]>wrote:

>
> Currently i'm learning to use C# at school.
> Last lesson I had learned about strings, and got some homework to get
> done.
> So here it is :
> 1) Make a function that will get two strings, check if they are the
> same, and then return false\true. (The teacher said "DO NOT USE
> STRING.COMPARE"). I tried do this one using FOR, but I always get out
> of the index bounds. (here is my function) :
>        static bool GetNCheck(string s, string p)
>        {
>            int o = s.Length-1;
>            int i = 0;
>            if (s[s.Length - 1] < p[p.Length - 1])
>                o = p.Length - 1;
>            for (; s[i] == p[i] && i < o; i++) ;
>            if (i == s.Length-1 && i == p.Length-1)
>                return true;
>            return false;
>        }
>
> 2)MAke a function that get a string, check if it have any numbers in
> it, and then return false\true.
>
> thanks :D
>

Reply via email to