C#字符串练习

            将字符串字符反输出
            string s = "1258955";
            char[] chs = s.ToCharArray();//将字符串数组转化为char数组
            for (int i = 0; i < chs.Length / 2; i++)
            {
                char temp = chs[i];
                chs[i] = chs[chs.Length - 1 - i];
                chs[chs.Length - 1 - i] = temp;


            }
            s = new string(chs);
            Console.WriteLine(s);
            Console.ReadKey();




            将“hello you world”反向输出“world you hello”
            string s = "hello you world";
            char[] chs = {' ','=' };
            string []str=s.Split(chs);//除去chs数组中不需要的字符
            string ss = "";
            for (int i = str.Length - 1; i >= 0; i--)
            {
               ss+=str[i]+" ";
                
            }
            Console.WriteLine(ss);
            Console.ReadKey();


            找用户名和域名
            string s = "1508602377@qq.com";
            int index = s.IndexOf('@');
            string usename = s.Substring(0, index);
            string yuming = s.Substring(index+1);
            Console.WriteLine("用户名{0},域名{1}",usename,yuming);
            Console.ReadKey();


            找出字符串中所有e所在的位置
            string s = "aghdeyeeeeeyeueyeieiueiueehjehjeejj";
            int index = s.IndexOf('e');
            Console.WriteLine("第一次出现的位置为{0}",index);
            while (index != -1)
            {
              index=s.IndexOf('e', index+1);
                Console.WriteLine(index);
            }
            Console.ReadKey();


            让用户输入一句话判断有没有邪恶两个字,有的话用**替换
            string s =  "老赵是个邪恶的人" ;
            
            if (s.Contains("邪恶"))
            {


                s = s.Replace("邪恶", "**");
            }
            Console.WriteLine(s);
            Console.ReadKey();


            把{“诸葛亮”,“鸟叔”,“卡哇伊”},变成诸葛亮|鸟叔|卡哇伊
            string[] s = { "诸葛亮", "鸟叔", "卡哇伊" };
      
            
           string ss = string.Join("|", s);
              
           
            Console.WriteLine(ss);
            Console.ReadKey();
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值