String manipulation

String manipulation

Postby Jeff Barnes » Tue Jul 31, 2018 4:51 pm

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?
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: String manipulation

Postby nageswaragunupudi » Thu Aug 02, 2018 6:59 pm

Code: Select all  Expand view
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
   
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10468
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: String manipulation

Postby Jeff Barnes » Thu Aug 02, 2018 7:23 pm

Thank you very much :D
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: String manipulation

Postby Carlos Mora » Wed Aug 08, 2018 6:40 pm

Hi Jeff,

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

KR

Carlos
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 989
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Jimmy and 50 guests