加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

c#对字符串进行大小写转换

(2010-05-06 00:11:58)
标签:

it

分类: c#学习

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyString
{
    class MyString
    {
        public string mystring
        {
            get;
            set;
        }
        public void upperTOlower()//大写转换为小写(功能同string.ToLower)
        {
            char[] str = mystring.ToCharArray();
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] <= 'Z'&&str[i]>='A')
                {
                    int v = 'a' - 'A';
                    int m = (int)str[i] + v;
                    str[i] = (char)m;
                }
                Console.Write(str[i]);
            }
        }
        public void lowerTOupper()//小写转换为大写(功能同string.ToUpper)
        {
            char[] str = mystring.ToCharArray();
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] <= 'z' && str[i] >= 'a')
                {
                    int v = 'a' - 'A';
                    int m = (int)str[i] - v;
                    str[i] = (char)m;
                }
                Console.Write(str[i]);
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            MyString s = new MyString();
            s.mystring = Console.ReadLine();
            s.lowerTOupper();
            Console.ReadKey();
        }
    }
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有