Saturday, May 22, 2010

How to swap to string variables without using third variable in c# or vb.net?

VB.NET





a %26amp;= b


b = a.Substring(0, a.Length - b.Length)


a = a.Substring(b.Length)

How to swap to string variables without using third variable in c# or vb.net?
It is String so in C# we can proceed like this





String name1 = "Yahoo";


String name2 = "Answers";








name1 = name1 + name2;





name2 = name1.substring(0,


(name1.length() - name2.length()));





name1 = name1.substring(name2.length() , name1.length());
Reply:For this you can use xor to swap





a = a^b


b= a^b


a= a^b





Lets take an more example:





A = 01111111


B = 01111101





A = A^B = 00000010


B = A^B = 01111111 (Original A)


A = A^B = 01111101 (Original B)

florist shop

No comments:

Post a Comment