常用字符串总结

  1. 字符串基础《一》
  2. static void Main(string[] args)
            {
                string str1 = "I Love You";
                string str2 = "这里是北京";
                string[] strArr = {"A","B","C","D","E","F" };
                char[] chr = { '1', '2', '3', '4', '5', '6' };
    
                string newValue = new string(chr); // 灵活将char数组组合成一个字符串:"123456"
    
                Console.WriteLine(newValue);
    
                newValue = new string('a', 2);  //重复输出前面的char字符,得到一个新的字符串:"aa"
    
                Console.WriteLine(newValue);
    
                int comNum = string.Compare(str1, str2);
                //如果str1 > str2 则返回1,否则返回 -1;等于返回0
    
                Console.WriteLine(comNum);
    
                newValue = string.Concat(str1, str2); //将两个字符串连接起来,组成新字符串
                Console.WriteLine(newValue);
    
               newValue = string.Format("{0}-{1}", str1,str2,chr[0]); //格式化输出,注意前面的占位符智能小于或等于后面的值
    
                Console.WriteLine(newValue);
    
                newValue = string.Join(",,", strArr);  //用两个逗号将字符串数组,组成新的字符串输出
    
                Console.WriteLine(newValue);
    
                bool isStrNull = string.IsNullOrEmpty(str1);  //判断字符串是否为空,不为空返回False,为空返回True
                Console.WriteLine(isStrNull);

猜你喜欢

转载自www.cnblogs.com/micc/p/10632576.html