hpcc-systems/HPCC-Platform — Issue #674: Wordbag service routines
Author: dabayliss
Created: 2011-10-13 14:32:05+00:00
State: open

We already have GetNthWord in our standard string libraries - SALT has getwords to get a range of words ...

The following three routines (which you are welcome to rename or rewrite is turbo-charged C++) return other useful parts of a wordbag

//Everything but the first
SHARED	NotFirst(STRING S) := IF(Str.FindCount(S,' ')=0,'',S[Str.Find(S,' ',1)+1..]);
// Everything but the last
SHARED	NotLast(STRING S) := IF(Str.FindCount(S,' ')=0,'',S[1..Str.Find(S,' ',Str.FindCount(S,' '))-1]);
// The string with the NNth item sliced out
SHARED	NotNN(STRING S,UNSIGNED2 NN) := MAP( NN = 1 => NotFirst(S),
NN = Str.WordCount(S) => NotLast(S),
S[1..Str.Find(S,' ',NN-1)]+S[Str.Find(S,' ',NN)+1..] );

I think they would be useful in the standard string libraries