diff --git a/routines/CharacterCounting.m b/routines/CharacterCounting.m index d021e77..4583ff5 100644 --- a/routines/CharacterCounting.m +++ b/routines/CharacterCounting.m @@ -1,23 +1,28 @@ ; https://www.isharkfly.com/t/mumps-character-counting/15224 - SET array("a")="adsakljasdira" - SET array("D")="DDD" - DO countCharsInAry(.array, .countByChar) + SET ary("1")="abcabc a" + SET ary("10")="abcabc aba" + ;SET ary("11")="abcabc aba" + + DO countCharsInAry(.ary, .countByChar) set name="" - f s name=$O(countByChar(name)) q:name="" w !,countByChar(name) + f s name=$O(countByChar(name)) q:name="" w !,name,">",countByChar(name) QUIT countCharsInAry(ary,countByChar) - SET name="" - FOR SET name=$O(ary(name)) QUIT:name="" DO SET countByChar(name)=$$getCount(ary(name),name) - QUIT -getCount(str,subStr) - SET count=0 - SET position=0 - - FOR { - SET position=$FIND(str, subStr, position) - QUIT:position=0 - SET count=count+1 - SET position=position - } - - QUIT count + S name="" + FOR SET name=$O(ary(name)) QUIT:name="" D + . W !,ary(name) + . S countByChar=$$getCount(ary(name)) + Q +getCount(str) + S countByChar="" + SET totalChars = 0 + FOR charIndex = 1:1:$LENGTH(str) DO + . S currentChar="" + . S currentChar = $EXTRACT(str, charIndex) + . W !,$DATA(countByChar(currentChar)) + . IF $DATA(countByChar(currentChar))'=1 DO + . . SET countByChar(currentChar) = 1 + . ELSE DO + . . SET countByChar(currentChar) = countByChar(currentChar) + 1 + . SET totalChars = totalChars + 1 + q countByChar