Extract string

Hi There

I created function to manage string as requirement  extract the first two letter of each word after space for example:

Text = "Review symptoms to report with patient"

After passed function it will be return "Resytorewipa"

ChangeFormat(desc)

   set desc = "Review symptoms to report with patient"
   q:$g(desc)=""
   SET delim=" "
   SET countdown=$LENGTH(desc,delim)
   set =1
   for
    {
        q:i>countdown
         set abbrv = $e($PIECE(desc,delim,i),1,2)   // But if I put w abbrv  I can get "Resytorewipa"
         set = i+1     
    }
   w abbrv

However, at the end I got only  abbrv=''pa"  how to get data as requirement.

 

Answers

set abbrv="" for i=1:1:$length(desc," ") set abbrv=abbrv_$zconvert($extract($piece(desc," ",i),1,2),"w")

delim " "abbrv ""
...
set abbrv abbrv $e($PIECE(desc,delim,i),1,2)   // But if I put w abbrv  I can get "Resytorewipa"
USER>set desc = "Review symptoms to report with patient"                        

USER>set abbrv = ##class(%Regex.Matcher).%New("([^\ ]{2})[^\ ]*\ ?",desc).ReplaceAll("$1")

USER>write abbrv
Resytorewipa