Instead of using hardcoded calls like I did in the code below, is it possible to have use a WRITE command within a For Loop to print out number of times each character is used? Below is what I have written, which will give me "A=n" but what I would like would be "A=n","B=n" etc without it being hardcoded.
CHARCOUNT
n str
f r !,"Enter patient's name: ",str q:str="" d
. s ^XPTNAME(str)=""
w #
f s str=$O(^XPTNAME(str)) q:str="" w !,"A = ",$L(str,"A")
q
Not sure exactly what you want to achieve but below some ideas.
COUNT() N array,char,key S key="" F S key=$O(^ZNAME(key)) Q:key="" D ; loop through all keys . S char="" . F I=1:1:$L(key) D ; loop through all letters .. S char=$E(key,I) ; extract the letter .. S array(char)=$G(array(char))+1 ; increment count S char="" F S char=$O(array(char)) Q:char="" D . W char,"=",array(char),! Q
Testing in GTM:
Although if you have Mixed case it can get different than you expect:
For this see the below code that may be specific to GTM ($ZCO function), also able to handle arrays or globals with limitation to single key/subscription:
Code (Attention that using arrays with name of the variable used internally in this label will not work, example "array","char","key","upper","where" since they will be newed):
Tested with global:
Tested with array:
Disabling force upper case:
If you want additional logic to include only character A to Z: