C# 字符串,小写转换成大写,大写转换成小写

public class ConvertCase
    {
        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' };
        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' };

        public static string getResult(string str) {

            StringBuilder result = new StringBuilder();
            string temp = str;
            for (int i = 0; i < temp.Length; i++)
            {
                int positionUpper = Array.IndexOf(x, temp[i]);
                if (positionUpper == -1)
                { //not upper char
                    int positionLower = Array.IndexOf(o, temp[i]);
                    if (positionLower == -1)
                    {
                        result.Append(temp[i]);
                        continue;
                    }
                    else
                    {
                        result.Append(x[positionLower]);
                        continue;
                    }
                }
                else {
                    result.Append(o[positionUpper]);
                    continue;
                }
            }
            

            return result.ToString();
        }
    }

 

posted @ 2017-04-18 09:48  xiaoyi.devil  阅读(456)  评论(0)    收藏  举报