Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

怎么split1列成3列

“2,4-滴异辛酯/2,4-D-ethylhexyl:7%;莠去津/atrazine:28%;乙草胺/acetochlor:42%”这字符串中三种有效成分,每种有效成分间用';'分隔。

t=table(["2,4-滴异辛酯/2,4-D-ethylhexyl:7%;莠去津/atrazine:28%;乙草胺/acetochlor:42%", "2,4-滴异辛酯1/2,4-D-ethylhexyl:7%;莠去津1/atrazine:28%;乙草胺1/acetochlor:42%"] as ContentInfo,1..2 as id )

select split(ContentInfo, ";") as `c1`c2`c3 from t

执行select语句报:

The first argument for 'split' must be scalar string。

然后我用each函数如下:

select each(split,ContentInfo, ";") as `c1`c2`c3 from t 

执行报错:

Not allowed to create a matrix with type STRING

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

def splitContent(msg){
    size=msg.size()
    result1=array(STRING,size,size)
    result2=array(STRING,size,size)
    result3=array(STRING,size,size)
    for(i in 0:size){
        m=split(msg[i],";")
        result1[i]=m[0]
        result2[i]=m[1]
        result3[i]=m[2]

    }
    return [result1,result2,result3]
}

select splitContent(ContentInfo) as `c1`c2`c3 from t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.7k users

...