c#学习笔记(十)-- 字符串函数

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

namespace 字符串函数
{
    class Program
    {
        static void Main(string[] args)
        {

            //大小写
            string s = "HELLO";
            string s1 = s.ToLower(); //转换为小写
            Console.WriteLine(s); //HELLO 字符串会变
            Console.WriteLine(s1);//hello

            s = s.ToLower(); //s指向新的字符串
            Console.WriteLine(s);//hello 

            s = s.ToUpper();
            Console.WriteLine(s);

            //去掉空白 只去两边的 不去中间的
            string s2 = " a b ";
            s2 = s2.Trim();
            Console.WriteLine("|{0}|",s2);

            //比较 是否相等 
            //==号  区分大小写
            bool b = ("abc" == "ABC");
            Console.WriteLine("b = {0}", b);

            b ="abc".Equals("ABC",StringComparison.OrdinalIgnoreCase);//忽略大小写
            Console.WriteLine("b = {0}", b);

            //比较大小
            int i = "abc".CompareTo("bcd");
            Console.WriteLine("i={0}",i);

            //分割
            string abc = "aaa,bbb,ccc,fdasasas";
            string[] strs = abc.Split(',');
            foreach (string str in strs)
            {
                Console.WriteLine("str = {0}",str);
            }

            //分割- 忽略空值
            string s3 = "aaa,bb,cc,,123,,3";
            string[] s4 = s3.Split(new char[]{','},StringSplitOptions.RemoveEmptyEntries);
            foreach (string s5 in s4)
            {
                Console.WriteLine(s5);
            }
           

            //分隔符是多个字符
            string s6 = "我是杰克逊我是迈克我是我是我是韩庚";
            string[] s7 = s6.Split(new string[] { "我是" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string s8 in s7)
            {
                Console.WriteLine(s8);
            }

            Console.ReadKey();
        }
    }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值