update #tempcolor set color_1 = dbo.func_strarraystrofindex(color,'/',1)
alter function [dbo].[func_strarraystrofindex]
@str varchar(1024), --要分割的字串
@split varchar(10), --分隔符號
@index int --取第幾個元素
returns varchar(1024)
asbegin
declare @location int
declare @start int
declare @next int
declare @seed int
declare @splitmaxint int --拆分組數上線
declare @result nvarchar(max)
set @str=ltrim(rtrim(@str))
set @start=1
set @next=1
set @seed=len(@split)
set @location=charindex(@split,@str)
set @splitmaxint=len(@str)-len(replace(@str,@split,''))+1
if @index> @splitmaxint or isnull(@str,'')=''
begin
set @result=''
endelse
begin
while @location<>0 and @index>@next
begin
set @start=@location+@seed
set @location=charindex(@split,@str,@start)
set @next=@next+1
endif @location =0 select @location =len(@str)+1
--這兒存在兩種情況:、字串不存在分隔符號2、字串中存在分隔符號,跳出while迴圈後,@location為,那預設為字串後邊有乙個分隔符號。
set @result=substring(@str,@start,@location-@start)
endreturn @result
end
字串轉陣列
將字串按某個字元切割成若干個字串,並以陣列形式返回 var s abc,abcd,aaa ss s.split 在每個逗號 處進行分解。console.log ss abc abcd aaa 擷取陣列中 720替換為 360 function changelargeimg self tophtml ...
php字串轉陣列函式,php字串轉陣列
php字串轉陣列 str split php 5,php 7 str split 將字串轉換為陣列 說明str split string string int split length 1 array 將乙個字串轉換為陣列。引數string 輸入字串。split length 每一段的長度。返回值如...
字串 字串轉數字
題目 將乙個字串轉換成數字。例如 123 123,71.02 71.02.方法一,直接呼叫庫函式atoi const char 和atof const char stoi string str include include int main 輸出結果 num int 435 num double ...