Page 1 of 1

String manipulation

Posted: Tue Jul 31, 2018 4:51 pm
by Jeff Barnes
I am trying to find a clean and simple way to manipulate a string.

I am sending an HL7 result message that contains a comment section.
In this comment section I am inserting my comment (var = cComment)
cComment can contain a paragraph or more.

The issue I'm having is, if the user enters their comment as one long string (ie: no CRLFs) the comment gets cut off.
If I add the "~" character to the HL7 message, it tells the system to add a CRLF.

So, the max length of the text before it gets cut off is 126 characters per line.
Now, the issue becomes, I can't just insert the "~" character every 126 characters because I do not want to start a new line in the middle of a word.
I need a way to look at the string, and if there is something other than a space where I need to insert the "~", move back until a space is found then insert the character and move to the next 126 character.

Any ideas?

Re: String manipulation

Posted: Thu Aug 02, 2018 6:59 pm
by nageswaragunupudi

Code: Select all

function Convert( cStr )

   local cOut := ""
   local nAt
   
   do while !Empty( cStr )
      if Len( cStr ) <= 125
         cOut  += cStr
         cStr  := ""
      else
         nAt   := RAT( " ", Left( cStr, 125 ) )
         if nAt == 0
            nAt   := 125
         endif
         cOut  += Left( cStr, nAt ) + "-"
         cStr  := SubStr( cStr, nAt + 1 )
      endif
   enddo
   
return cOut
   

Re: String manipulation

Posted: Thu Aug 02, 2018 7:23 pm
by Jeff Barnes
Thank you very much :D

Re: String manipulation

Posted: Wed Aug 08, 2018 6:40 pm
by Carlos Mora
Hi Jeff,

have you tried the MemoLine() function + PadR()? I think it will do what you are looking for.

KR

Carlos