zoukankan      html  css  js  c++  java
  • C# subString的理解

            public void TestMethod1()
            {
                string str = "ABCDEFGHIJKLMN";

                string result = str.Substring(2); //CDEFGHIJKLMN

                string result1 = str.Substring(2, 3); //CDE

                Console.ReadKey();
                //string result2 = str.Substring();
            }

    将subString(index,length)第一个参数看做从1开始的索引,将index位置的之前的字符都给截掉,length表示从索引位置截取字段的长度,若不指定长度,则截取字段到字符串末尾。

    length的最大长度为str.length-index!

    --sql server 中substring()函数

    select SUBSTRING('abcde',0,2);--a
    select SUBSTRING('abcde',0,5);--abcd
    select SUBSTRING('abcde',1,2);--ab
    select SUBSTRING('abcde',-1,5);--abc

    select SUBSTRING('abcdefghijk',3,5);--cdefg

    SUBSTRING(str,start,length) :表示str数据源,str计数位置默认从1开始,截取的字段为从 start开始的 length个字符(包括start);字符串截取start到 start+length-1位置的字符,起始位置若为0,或者小于0,则进行补全再截取长度

    实例:

    select top 5 substring(ApprovalUser,charindex('',ApprovalUser)+1 ,
    LEN(ApprovalUser)) as [Last Name] from CustomerBase

  • 相关阅读:
    iOS设计模式-工厂方法
    iOS设计模式-原型模式
    (转)iOS 屏幕适配
    iOS设计模式-MVC
    转 常用第三方库
    学习资料收集
    xcode 插件
    CocoaPods安装和使用
    iOS 友盟统计的bug分析
    HTML——表格
  • 原文地址:https://www.cnblogs.com/Unrmk-LingXing/p/4139517.html
Copyright © 2011-2022 走看看