"Go" C # string case mixed conversion

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.