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();
}
}
}
c#学习笔记(十)-- 字符串函数
最新推荐文章于 2024-08-07 13:07:53 发布