C#小白学习笔记(7)字符串处理2

namespace Demo07_字符串处理2
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] ch = { ' ', 'a', 'B', 'g' };
            string str = "abcdefg";
            Console.WriteLine(str);
            Console.WriteLine(str.Substring(0,3));
            Console.WriteLine(str.Insert(1, "HHH"));//在指定索引位置插入字符串
            Console.WriteLine(str.Remove(3,2));//从索引位置开始删除字符串的长度
            Console.WriteLine(str.Replace("b","h"));//把str中的b换成h

            string str1 = null;
            string str2 = ""; //等同于上一个语句
            Console.WriteLine(string.IsNullOrEmpty(str1)); //判断指定字符串是否为空
            Console.ReadKey();
        }
    }
}

运行结果如下:

 

posted @ 2020-09-16 15:01  ___lucky  阅读(90)  评论(0)    收藏  举报