将英文的字母换成大写字母开头

3683人阅读 2021/3/9 20:05 总访问:651782 评论:0 收藏:0 手机
分类: Csharp
          
          
            Console.WriteLine("请输入英文,中间用空格隔开");
            //定义变量接受
            string English = Console.ReadLine();
            //根据空格分割
            string[] letter = English.Split(' ');
            string str = "";
            for (int i = 0; i < letter.Length; i++)
            {
               //判断是否是多个连续空格,去除空格
                if (letter[i].ToString() == "")
                {
                    continue;
                }
                //将数组不是空格的值开头字母大写,后面字母小写
                letter[i] = letter[i].Substring(0, 1).ToUpper() + letter[i].Substring(1).ToLower();
                //拼接字符串
                str += letter[i];
            }
            Console.WriteLine(str);


评价
脚踏实地,一步一个脚印
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术