If there was a built-in function for expanding the list into a table, then the solution would be even shorter.
An example of such a function:
Class dc.golf.Kata [ Abstract ]
{
Query split(
s As %VarString,
delim As %VarString) As %Query(ROWSPEC = "word:%String") [ SqlProc ]
{
}
ClassMethod splitExecute(
ByRef qHandle As %Binary,
s As %VarString,
delim As %VarString) As %Status
{
d ##class(%ListOfDataTypes).BuildValueArray($lfs(s,delim),.qHandle)
s qHandle=0
q $$$OK
}
ClassMethod splitFetch(
ByRef qHandle As %Binary,
ByRef Row As %List,
ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = splitExecute ]
{
s d=$o(qHandle(qHandle),1,v)
i d="" { s AtEnd=1 } else { s Row=$lb(v),qHandle=d }
q $$$OK
}
}Now you can do a variety of things with the string, for example:
select min(length(word)) "min",length(word) len,word from dc_golf.Kata_split('bitcoin take over the world maybe who knows perhaps',' ')Result:
| min | len | word |
|---|---|---|
| 3 | 7 | bitcoin |
| 3 | 4 | take |
| 3 | 4 | over |
| 3 | 3 | the |
| 3 | 5 | world |
| 3 | 5 | maybe |
| 3 | 3 | who |
| 3 | 5 | knows |
| 3 | 7 | perhaps |
- Log in to post comments
