zoukankan      html  css  js  c++  java
  • 字符串分隔(转自别处)

    CREATE FUNCTION [dbo].[GetSplitOfIndex]
    (
          @String NVARCHAR(MAX) ,  --要分割的字符串
          @split NVARCHAR(10) ,  --分隔符号
          @index INT --取第几个元素
    )
    RETURNS NVARCHAR(1024)
    AS
        BEGIN
            DECLARE @location INT
            DECLARE @start INT
            DECLARE @next INT
            DECLARE @seed INT
     
            SET @String = LTRIM(RTRIM(@String))
            SET @start = 1
            SET @next = 1
            SET @seed = LEN(@split)
     
            SET @location = CHARINDEX(@split, @String)
            WHILE @location <> 0
                AND @index > @next
                BEGIN
                    SET @start = @location + @seed
                    SET @location = CHARINDEX(@split, @String, @start)
                    SET @next = @next + 1
                END
            IF @location = 0
                SELECT  @location = LEN(@String) + 1
     
            RETURN SUBSTRING(@String,@start,@location-@start)
        END

  • 相关阅读:
    uva 1605 building for UN ——yhx
    uva 120 stacks of flapjacks ——yhx
    uva133-S.B.S.
    Uva10082 WERTYU -S.B.S.
    Quicksum-S.B.S.
    NOIP2014提高组 DAY1 -SilverN
    NOIP2013普及组 -SilverN
    uva 1354 Mobile Computing ——yhx
    UVa 11292 Dragon of Loowater
    UVa 839 Not so Mobile
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/2299214.html
Copyright © 2011-2022 走看看