C# 字符串常见函数

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

namespace _09字符串的常用方法
{
    class Program
    {
        static void Main(string[] args)
        {
            //string s = null;
            //if (string.IsNullOrEmpty(s))
            //{
            //    Console.WriteLine("是的");
            //}
            //else
            //{
            //    Console.WriteLine("不是");
            //}

            //string str = "abcdefg";

            //Console.WriteLine(str[5]);
            //Console.ReadKey();

            //char[] chs = str.ToCharArray();
            //chs[2] = 'z';
            //foreach (char item in chs)
            //{
            //    Console.WriteLine(item);
            //}
            char数组---->字符串
            //str = new string(chs);

            //string str = "abCDEfg";
            //Console.WriteLine(str.ToUpper());
            //Console.WriteLine(str.ToLower());

            //string s1 = "aBc";
            //string s2 = "Abc";
            //if (s1 == s2)
            //{
            //    Console.WriteLine("相等");
            //}
            //else
            //{
            //    Console.WriteLine("不相等");
            //}
            //Console.ReadKey();

            //类的Equals方法可以重写
            //if (s1.Equals(s2))
            //{
            //    Console.WriteLine("相等");
            //}
            //else
            //{
            //    Console.WriteLine("不相等");
            //}
            //Console.ReadKey();
            //Console.ReadKey();


            //string str = "老毕吃了一顿饭,结果老毕火了";
            int index = str.IndexOf("老",11);
            Console.WriteLine(index);
            //int index = str.LastIndexOf("123");
            //Console.WriteLine(index);
            //Console.ReadKey();


            //string str = "老毕吃了一顿饭,结果老毕火了";
            //int index = str.IndexOf(",");
            //string strNew = str.Substring(index + 1);
            //Console.WriteLine(strNew);

            //string str = "张  ,,--三   ,李,,--四  a  ";
            //string[] strNew = str.Split(new char[] { ',', ' ', '-' },StringSplitOptions.RemoveEmptyEntries);
            字符串--->char类型的数组 ToCharArray()
            字符串--->string类型的数组
            //Console.ReadKey();

            //Trim() TrimEnd() TrimStart()

            //string s = "   张   ,,,--    三 ,,,--   ";

            //Console.Write(s.Trim(' ',',','-'));


            //string[] names = { "金秀贤", "金贤秀", "金正日", "金正恩" };
            金秀贤|金贤秀|金正日|金正恩

            //string res = string.Join("|", 'c', "张三", 100, 3.14, true, 5000m);
            //Console.WriteLine(res);
            //Console.ReadKey();
            //string res = string.Empty;
            //for (int i = 0; i < names.Length - 1; i++)
            //{
            //    res += names[i] + "|";
            //}
            //Console.WriteLine(res + names[names.Length - 1]);

            Console.WriteLine("请输入你要回复的内容");
            string contents = Console.ReadLine();
            //判断contents中是否包含敏感词
            if (contents.Contains("老赵"))
            {
                contents = contents.Replace("老赵", "****");
            }
            Console.WriteLine(contents);
            Console.ReadKey();
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值