October 23, 2015, 09:43 AM
Asad [SOLVED] COUNT of words which are seperated by a seperator
I need to do a count of individual words in a column which are seperated by ','. For Example if the column has value
word1, word2
the function should give me COUNT 2. Can this be achieved?
This message has been edited. Last edited by: <Kathryn Henning>, October 30, 2015 01:39 PM October 23, 2015, 10:42 AM
krish Please refer the url October 26, 2015, 07:38 AM
Asad That helped but problem is I am searching for words which cannot be predefined. How would I search for the words separated by a ',' and increase count for every word encountered?
October 26, 2015, 08:17 AM
Asad ok I used the logic of counting the seperator and then incrementing the total count by 1 and that gives me the correct total. I think it is a temp solution? Is there a more concrete way? I used this
DEFINE FUNCTION COUNT_CHARS DESCRIPTION (CHAR/A1,STRING/A4000V)
_BEFORE/I4 = ARGLEN(4000,STRING,'I4');
STRIPPED/A4000V = STRIP(4000,STRING,CHAR,'A4000V');
_AFTER/I4 = ARGLEN(4000,STRIPPED,'I4');
COUNT_CHARS/I4 = _BEFORE - _AFTER + 1;
END
October 26, 2015, 12:59 PM
GavinL As far as I know, that is about as good as it gets.
DEFINE FUNCTION COUNT_CHARS DESCRIPTION (CHAR/A1,STRING/A4000V)
_BEFORE/I4 = ARGLEN(4000,STRING,'I4');
STRIPPED/A4000V = STRIP(4000,STRING,CHAR,'A4000V');
_AFTER/I4 = ARGLEN(4000,STRIPPED,'I4');
COUNT_CHARS/I4 = _BEFORE - _AFTER + 1;
END
DEFINE FILE CAR
MYVALUES/A200='1fff,2fff,3fff,4fff,5fff,6fff,7fff,8fff,9fff,10fff,11fff,12fff';
MYCOUNT/I4=COUNT_CHARS(',', MYVALUES);
FIELD9/A50=GETTOK(MYVALUES, 200, 9, ',', 50, 'A50');
FIELD10/A50=GETTOK(MYVALUES, 200, 10, ',', 50, 'A50');
FIELD11/A50=GETTOK(MYVALUES, 200, 11, ',', 50, 'A50');
END
TABLE FILE CAR
PRINT
CAR.ORIGIN.COUNTRY NOPRINT
MYVALUES
MYCOUNT
FIELD9
FIELD10
FIELD11
-*WHERE RECORDLIMIT EQ 1
ON TABLE SET PAGE-NUM NOLEAD
ON TABLE NOTOTAL
ON TABLE PCHOLD FORMAT HTML
END