Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Board,
Does anyone know how to find the first occurrence in a string that is not the one specified - e.g. I have a string
'ZZZZZZ1234'
and I would like to find the position of the first occurrence that is not 'Z' (i.e. '7'). There are lots of functions that allow locating a specific string but I can't find one that does the opposite. Note the above is just an example so I can't just look for '1' as this could be any character that isn't 'Z'.
Hi,
How about using Replace(Word,'Z','') to get the string without the Zs, then take the length of the new field away from that of the original field, e.g.:
Word_TMP:
Load * Inline
[Word
'ZZZZZZ1234'];
Word:
Load *,
Len(Word)-Len(NoZs) as "FirstOccurenceNoZs";
Load
Word,
Replace(Word,'Z','') as "NoZs"
Resident Word_TMP;
Drop Table Word_TMP;
You could use the same approach directly in the chart, but it won't be as efficient since it will have to perform the operation in memory:
=Len(Word)-Len(Replace(Word,'Z',''))
Hi,
How about using Replace(Word,'Z','') to get the string without the Zs, then take the length of the new field away from that of the original field, e.g.:
Word_TMP:
Load * Inline
[Word
'ZZZZZZ1234'];
Word:
Load *,
Len(Word)-Len(NoZs) as "FirstOccurenceNoZs";
Load
Word,
Replace(Word,'Z','') as "NoZs"
Resident Word_TMP;
Drop Table Word_TMP;
You could use the same approach directly in the chart, but it won't be as efficient since it will have to perform the operation in memory:
=Len(Word)-Len(Replace(Word,'Z',''))