String manipulation
Curious if there is a string function which can transform a delimited string into an array without looping through $Piece...such as "a,b,c,d,e,f" into array(0)=5,array(1)="a",array(2)="b" etc
Curious if there is a string function which can transform a delimited string into an array without looping through $Piece...such as "a,b,c,d,e,f" into array(0)=5,array(1)="a",array(2)="b" etc
There are not such methods, we only have function which converts delimited string to $listbuild format and back. And you can do it in this way, without any looping, but only if you already know how many items you have.
Maybe the lack of line indent in Marc's post confused you. Try this:
%Split(List,Array,del) ;;liberating a VB function S del=$G(del,"|") Do ##class(%ListOfDataTypes).BuildValueArray($lfs(List,del),.Array) Q 1
# 1
d ##class(%ListOfDataTypes).BuildValueArray($lfs("a,b,c,d,e,f"),.array)
s array(0)=$o(array(""),-1)
zw array
# 2
s list=##class(%ListOfDataTypes).%New()
d list.InsertList($lfs("a,b,c,d,e,f"))
m array=list.Data
s array(0)=list.Count()
zw array
The Result for both variant:
array(0)=6
array(1)="a"
array(2)="b"
array(3)="c"
array(4)="d"
array(5)="e"
array(6)="f"
very slick....for you old Mumpsters, here's an extrinsic function
%Split(List,Array,del) ;;liberating a VB function
S del=$G(del,"|")
Do ##class(%ListOfDataTypes).BuildValueArray($lfs(List,del),.Array)
Q 1
I suppose the problem is my cache version.
But i can't compile the code with the line: "%Split(List,Array,del) ;;liberating a VB function"
Btw nice point on Mumpsters lol
What's VB got to do with this?