+ 1
How to use this operator ^. Example: c[0] ^ 32;What this mean??
Ex. string str; public void readdata() { Console.Write("Enter a String : "); str = Console.In.ReadLine(); } public void abbre() { char[] c, result; int j = 0; c = new char[str.Length]; result = new char[str.Length]; c = str.ToCharArray(); result[j++] = (char)((int)c[0] ^ 32); result[j++] = '.';
4 Antworten
+ 3
Short answer
It toggles the upper/lower case
letter
Long answer
The ^ operator was used to perform XOR bitwse operation. As you can see at this line the character was cast into integer and back to character again after apply XOR with 32:-
(char)((int)c[0] ^ 32)
Let's say you got a character 'C', its binary representation is 100 0011.
100 0011 ^ 010 0000 = 110 0011.
which represents the character 'c'. Take note that if you apply the operation again you'll get back the original letter.
P/S: You can refer to the ASCII table to find out the number representation of characters. (e.g. A = 65, a = 97 etc.)
💡 Demo
https://code.sololearn.com/cPeyh9v4EjtN/?ref=app
+ 2
I don't know anything about C# But "^" is usually the "power of" operator. meaning 3^3 is the same as 3 * 3 * 3 which equals 27
+ 1
Thank u very much.
Complete answer Zephyr Koo.
0
Thank u Timothy Edge.