Page 1 of 1

How to remove CRLF from a string

Posted: Tue Jul 01, 2025 10:39 am
by Tiger
I get a string from excel and I need to remove the CRLF from the string. I test following codes but it can't work... :(

G_VISITOR := ALLTRIM(Cell2CHR(aExcel[i,2]))
IF AT(CHR(13)+CHR(10), G_VISITOR) > 0
STRTRAN(G_VISITOR,CHR(13)=cHR(10),"")
ENDIF

Thanks for any help.

Re: How to remove CRLF from a string

Posted: Tue Jul 01, 2025 10:42 am
by Tiger
Sorry , a typo .... STRTRAN(G_VISITOR,CHR(13)+cHR(10),"")

Re: How to remove CRLF from a string

Posted: Tue Jul 01, 2025 3:15 pm
by ASESORMIX
G_VISITOR := STRTRAN(G_VISITOR,CHR(13)+cHR(10),"")

Re: How to remove CRLF from a string

Posted: Wed Jul 02, 2025 11:24 am
by Tiger
Thanks for your help, but it can't work...

what I want is to convert following string to single line.

From

AA、
BB、
CC、
DD、
EE、
FF、
GG

To

AA、BB、CC、DD、EE、FF、GG

Thanks.

Re: How to remove CRLF from a string

Posted: Wed Jul 02, 2025 2:33 pm
by ASESORMIX

Code: Select all


SALTO := CHR(13)+CHR(10)

G_VISITOR := "AA,"+SALTO+"BB,"+SALTO+"CC,"+SALTO+"DD,"+SALTO+"EE,"+SALTO
MSGDEBUG( G_VISITOR  )
MSGINFO( G_VISITOR  )

G_VISITOR := STRTRAN( G_VISITOR, SALTO ,"")    
MSGDEBUG( G_VISITOR  )
MSGINFO( G_VISITOR  )


Re: How to remove CRLF from a string

Posted: Wed Jul 02, 2025 2:38 pm
by ASESORMIX
Surely, there is another character present. this character could be a tab ( chr(9) )

Re: How to remove CRLF from a string

Posted: Wed Jul 02, 2025 6:37 pm
by edk
IMHO better solution is to use G_VISITOR := hb_StrReplace( G_VISITOR, CRLF, "")
This function will remove all CR and/or LF

Re: How to remove CRLF from a string

Posted: Thu Jul 03, 2025 1:07 am
by Tiger
Many thanks for all your help, now it works by using this function hb_StrReplace( G_VISITOR, CRLF, "")