FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour String manipulation
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
String manipulation
Posted: Tue Jul 31, 2018 04: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)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: String manipulation
Posted: Thu Aug 02, 2018 06:59 PM
Code (fw): Select all Collapse
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
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: String manipulation
Posted: Thu Aug 02, 2018 07:23 PM

Thank you very much :D

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 989
Joined: Thu Nov 24, 2005 03:01 PM
Re: String manipulation
Posted: Wed Aug 08, 2018 06: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"

Continue the discussion