C # string Case mixed conversion
I am a. Net Meng new, in the university is the computer science of the comparison miscellaneous out ready to go net direction training for two months
Today, it was a very simple question. Enter a character if it is uppercase convert to lowercase if lowercase then convert to uppercase
The difficulty is that later we spontaneously extend and find that there is no solution for this situation on the Internet
So I wrote myself a way to deal with this. Class sends up to share the lower than the self-contained conversion method more without a key point and can be mixed for the case of the string
such as ASDFASF$%#%^645765127AAFSAASDFASD
In this case, it is very complicated to convert the upper capitalization to lowercase and lowercase to uppercase.
It's not very practical, but it's been searched on the internet, and there's a lot of people looking for it, but there's no easy way out.
So write a conversion that adapts to any mixed case to convert each other and not find any bugs in the test
Although I do not know how many places can be used, but since Baidu so many people want to share under it
———— It's really important to share your programming ideas with the same new people.
1 class Subna 2 {3 private static char[] x = {' Q ', ' W ', ' E ', ' R ', ' T ', ' Y ', ' U ', ' I ', ' O ', ' P ', ' A ', ' S ', ' D ', ' F ', ' G ', ' H ', ' J ', ' K ', ' L ', ' Z ', ' X ', ' C ', ' V ', ' B ', ' N ', ' M '}; 4 private static char[] o = {' Q ', ' W ', ' e ', ' r ', ' t ', ' y ', ' u ', ' i ', ' o ', ' P ', ' a ', ' s ', ' d ', ' f ', ' g ', ' H ', ' J ', ' K ', ' l ', ' Z ', ' x ', ' C ', ' V ', ' b ', ' n ', ' m '}; 5 6 7 8 public static string GetResult (String zz) 9 {Ten StringBuilder de = new StringBuilder (); string zi = zz;13 for (int i = 0; i < Zi. Length; i++) {bol = Array.indexof (x, Zi[i]), + if (bol = =-1) 17 {Bol2 int = Array.indexof (o, zi[i]), if (bol2 = =-1) 20 {$ de. Append (Zi[i]); continue;23}24 Else25 {26 for (int da = 0; da < o.length; da++) (O [da] = = Zi[i]) Append (X[da]); break;32}33}34 }35}36 else37 {$ for (int da = 0; da < X.length; da++) ((x[da] = = Zi[i]) 41 {42 De. Append (O[da]); break;44}45}46 }47}48 return de. ToString (); 50 51}52 53}
This is the class I've encapsulated.
is a static method that only uses the call to pass the argument.
Such as
Console.WriteLine ("\ n Please enter a string to convert case:");
String Zi = Console.ReadLine ();
String de = Zi. ToUpper ();
Console.WriteLine ("\ n Conversion case is: {0}", de);
One-click Call mixed Conversion I hope to give the same Moe new learning convenience
"Go" C # string case mixed conversion