//String 字符串的常见操作
        public static void Fun1()
        {
            string MyStr = " Hello World! ";

            //length长度属性
            Console.WriteLine(MyStr.Length);

            //Substring()截取
            Console.WriteLine(MyStr.Substring(, ));

            //ToCharArray()转换为字符数组
            char[] charr = MyStr.ToCharArray();

            //ToUpper()转换大写
            string UpperStr = MyStr.ToUpper();
            Console.WriteLine("转换为大写:" + UpperStr + "\n");

            //ToLower()转换小写
            Console.WriteLine("转换为小写:" + MyStr.ToLower());

            //TrimStart() and TrimEnd() 去掉字符左右边的空格 TrimStart--去掉左边
            string LefStr = MyStr.TrimStart();
            string RigStr = MyStr.TrimEnd();

            Console.WriteLine("左边 " + LefStr + "\n" + "右边 " + RigStr + "\n");

            //Replace()替换字符
            string ReplaceStr = MyStr.Replace('W', 'M');
            Console.WriteLine("替换字符 " + ReplaceStr + "\n");

            //Concat()连接字符
            string concatStr = string.Concat(MyStr, "asas", "asasa");
            Console.WriteLine("连接字符 " + concatStr + "\n");

            //IsNullOrEmpty()判断空值
            bool NullorEmpty = string.IsNullOrEmpty(MyStr);
            Console.WriteLine("判断空值 " + NullorEmpty.ToString() + "\n");

            //StartsWith()开头
            Console.WriteLine(MyStr.StartsWith(" ") == true);

            //EndsWith()结尾
            bool endwith = MyStr.EndsWith(" ");
            Console.WriteLine("结尾 " + endwith.ToString() + "\n");

            //IndexOf() and LastIndexOf()字符串的位置
            string strLocation = "123abc4c56efd";
            Console.WriteLine(') + "\n");
            Console.WriteLine("LastIndexOf:" + strLocation.LastIndexOf('c') + "\n");

            //插入字符
            Console.WriteLine(MyStr.Insert(, "W"));

            //MyStr.PadLeft();MyStr.PadRight()

            //Remove()移除
            Console.WriteLine(, ) + "\n");

            //Format()格式化
            );
            Console.WriteLine(str);

            //Compare()和CompareTo() 比较方法
            string strA = "File.exe";
            ";

            int numA = string.Compare(strA, strB);
            Console.WriteLine("Compare: " + numA.ToString() + "\n");

            int numB = strA.CompareTo(strB);
            Console.WriteLine("CompareTo: " + numB.ToString());

            //比较两个指定的 System.String 对象。
            // 返回结果:
            // 一个 32 位有符号整数,指示两个比较数之间的词法关系。
            //值条件小于零 strA 小于 strB。 零strA 等于 strB。 大于零 strA大于 strB。 

        }

常用的就这些吧,有好的话我在补上!!!

C#入门篇6-2:字符串操作 string常用的函数的更多相关文章

  1. C#入门篇6-1:字符串操作 char常用的函数

    //char 字符的常见操作 public static void FChar() { //判定字符的类别 char ch1 = 'a';//使用小引号 bool bl = true; bl = ch ...

  2. C#入门篇6-4:字符串操作 string分割字符串效率比较

    //分割字符串效率比较 public static void Fund() { //1.用string.Split方法 //a.字节数组: //625毫秒/百万次 string str1 = &quo ...

  3. C#入门篇6-3:字符串操作 string的ToString() Split()和Copy()方法

    //ToString()方法 public static void OutPut() { //字符型转换 转为字符串 Console.WriteLine(.ToString("n" ...

  4. C#入门篇6-6:字符串操作 StringBiulder string char[]之间的转化

    //StringBiulder string char[]之间的转化 public static void Fun3() { StringBuilder sb = new StringBuilder( ...

  5. C#入门篇6-8:字符串操作 深入研究字符串的内存驻留机制

    //字符串的内存驻留机制 public static void Test() { //当有多个字符串变量包含了同样的字符串实际值时, //CLR可能不会为它们重复地分配内存,而是让它们统统指向同一个字 ...

  6. C#入门篇6-11:字符串操作 查找与替换

    #region 查找与替换 public class C4 { //查找 public static void StrFind() { //目标字符串 string str1 = "~awe ...

  7. C#入门篇6-10:字符串操作 DateTime操作

    #region DateTime操作 public class C3 { //DateTime常用的操作 public static void Fun1() { //格式:2012-8-16 11:2 ...

  8. C#入门篇6-9:字符串操作 不值一提的函数【不看也行】

    // 判断输入的是否全是数字:返回结果:true:全是数字:false:有字幕出现 public static bool Isaccord1(string str) { bool bl = true; ...

  9. C#入门篇6-7:字符串操作 看看字符串的特殊之处 值类型与引用类型的区别

    //看看字符串的特殊之处值类型与引用类型的区别 public static void CompareString(string stra, string strb, int i) { #region ...

随机推荐

  1. 修改Oracle环境变量$PATH

    此次在创建公司的Oracle 标准化应用时,提到了添加$PATH,但没有发现对我很符合我的现况的方法,现记录下此次添加$PATH的方法: 首先查看$PATH中是否已存在我们需要的路径: 执行指令ech ...

  2. Paoding-Rose学习

    * HttpServletRequest.getContextPath 获取web程序root.如果是默认位置,返回””空串,否则返回 /根路径名 * rose是如何扫描到资源的 利用spring提供 ...

  3. 部署JavaWeb时出现 If a file is locked,you can wait until

    在部署JavaWeb程序时出现了if a file is locked ,you can wait until the lock stop的问题,这个主要是classpath目录出错或者jar包未导入 ...

  4. dac verilog ad5601

    首先从官网下载数据手册.DAC有串行有并行,ad5601是串行,(需要好多时钟沿的移位内部转换为并行在输出). 按照手册的时序编写程序, 关注下芯片的波特率范围 看看手册的数据传输那些事有效的数据位 ...

  5. pta 编程题12 堆中的路径

    其它pta数据结构编程题请参见:pta 这道题考察的是最小堆. 堆是一个完全二叉树,因此可用数组表示,一个下标为 i 的结点的父节点下标为 i / 2,子结点下标为 2i 和 2i + 1. 插入元素 ...

  6. 工作流性能优化(敢问activiti有扩展性?)(1)

    工作流待办(首页待办列表),加载缓慢,activiti本机,看了代码又是全部数据加载到内存,然后代码过滤,我为什么又说又呢? 用VisualVM做性能测试:   之前同事给的解决方案: 1.把&quo ...

  7. IOS 绘制基本图形(画文字、图片水印)

    - (void)drawRect:(CGRect)rect { // Drawing code // [self test]; // 1.加载图片到内存中 UIImage *image = [UIIm ...

  8. hdu-1532 Drainage Ditches---最大流模板题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1532 题目大意: 给出有向图以及边的最大容量,求从1到n的最大流 思路: 传送门:最大流的增广路算法 ...

  9. sparkSQL中udf的使用

    在Spark中使用sql时一些功能需要自定义方法实现,这时候就可以使用UDF功能来实现 多参数支持 UDF不支持参数*的方式输入多个参数,例如String*,不过可以使用array来解决这个问题. 定 ...

  10. double类型的小数,四舍五入保留两位小数

    import java.math.BigDecimal; public class Kewai{ public static void main(String[] args) { double f = ...