diff --git a/routines/.gitkeep b/routines/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/routines/CharacterCounting.m b/routines/CharacterCounting.m new file mode 100644 index 0000000..d021e77 --- /dev/null +++ b/routines/CharacterCounting.m @@ -0,0 +1,23 @@ + ; https://www.isharkfly.com/t/mumps-character-counting/15224 + SET array("a")="adsakljasdira" + SET array("D")="DDD" + DO countCharsInAry(.array, .countByChar) + set name="" + f s name=$O(countByChar(name)) q:name="" w !,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