首页 > 其他 > 详细

常用字符串总结

时间:2019-03-31 19:15:00      阅读:136      评论:0      收藏:0      [点我收藏+]
  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);

     

常用字符串总结

原文:https://www.cnblogs.com/micc/p/10632576.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!