REPLACE and CHR(10) in Windows

Posted by jquerijero on 23-May-2014 14:38

I can't seem to find the documentation on the REPLACE function regarding replacing with CHR(10). When run Windows, CHR(10) ends up as CHR(13) + CHR(10). When run on UNIX, CHR(10) is just CHR(10).

The behavior seems to be non-portable. Is this expected? 

All Replies

Posted by Thomas Mercer-Hursh on 23-May-2014 16:09

Use "~n" instead.  That will be OS appropriate.

Posted by jquerijero on 23-May-2014 16:14

That will not solve the CHR(10) replacement issue when you just want to truly replace something with CHR(10).

Posted by Thomas Mercer-Hursh on 23-May-2014 16:22

Meaning that you want to run on Windows and create a Unix style file?

Posted by jquerijero on 23-May-2014 16:47

Somewhat but the opposite (Windows style text).

I'm basically creating a normalization routine to a Windows (CR + LF) configuration regardless if the routine was run under UNIX or Windows. I can detect OPSYS to mitigate the problem. I'm just a little surprised about CHR(10) conversion because the REPLACE function documentation doesn't mention it.

Posted by Matt Gilarde on 24-May-2014 03:55

Can you provide code that demonstrates what you're seeing? I can't get the same results and I don't see anything in the CHR or REPLACE functions that would cause it.


a = REPLACE(a, "b", CHR(10)).


This code shows:

97 10 99

If I write the string to a file the LF is converted to CR/LF, but that conversion can be avoided with the BINARY option on the OUTPUT TO statement.

Posted by jquerijero on 27-May-2014 09:24

I'm writing to MEMPTR using PUT-STRING. Will that be the same as writing to a file?

Posted by Matt Gilarde on 27-May-2014 09:47

I don't think PUT-STRING would cause this either. Could you demonstrate it with a short program?

Posted by jquerijero on 28-May-2014 09:14

My issue was coming from the OUTPUT TO.

Does COPY-LOB have the same issue?

This thread is closed