Discussion:
How to remove CR/LF characters from a string
(too old to reply)
Andreas Völp
2007-04-04 08:32:39 UTC
Permalink
In SPSS 15, I have a data set (improted from MS Access via ODBC) with
several string variables some of which contain cariage return / line feed
(CR/LF) characters. In text-based reports these characters cause a
disruption of the column alignment, and therefore I would like to remove
them from the strings (by replacing CR/LF by a blank).

How can I do this? I couldn't find any way of specifying the CR/LF
characters so that I can use them in a COMPUTE command. Isn't there anything
like an ANSI or ASCII function that allows me to refer to these characters
by their character table numbers?
--
Andreas Völp

Psy Consult Scientific Services
Frankfurt, Germany
peter m sopp
2007-04-04 09:52:16 UTC
Permalink
Two possible ways:
- external editor (like Xemacs) (with export and re-import data - that's
the way I've solved some similar problems)
- python (should work I think - someone with an idea?)
Peter
Post by Andreas Völp
In SPSS 15, I have a data set (improted from MS Access via ODBC) with
several string variables some of which contain cariage return / line feed
(CR/LF) characters. In text-based reports these characters cause a
disruption of the column alignment, and therefore I would like to remove
them from the strings (by replacing CR/LF by a blank).
How can I do this? I couldn't find any way of specifying the CR/LF
characters so that I can use them in a COMPUTE command. Isn't there anything
like an ANSI or ASCII function that allows me to refer to these characters
by their character table numbers?
JKPeck
2007-04-04 12:14:32 UTC
Permalink
Post by peter m sopp
- external editor (like Xemacs) (with export and re-import data - that's
the way I've solved some similar problems)
- python (should work I think - someone with an idea?)
Peter
Post by Andreas Völp
In SPSS 15, I have a data set (improted from MS Access via ODBC) with
several string variables some of which contain cariage return / line feed
(CR/LF) characters. In text-based reports these characters cause a
disruption of the column alignment, and therefore I would like to remove
them from the strings (by replacing CR/LF by a blank).
How can I do this? I couldn't find any way of specifying the CR/LF
characters so that I can use them in a COMPUTE command. Isn't there anything
like an ANSI or ASCII function that allows me to refer to these characters
by their character table numbers?
For clarity, this code deals with the cr and lf separately, Change
the second line to use '' as the replacement character if you want
only a single blank.


compute strvar = replace(strvar, string(10, ib1),' ').
compute strvar = replace(strvar, string(12, ib1),' ').

HTH,
Jon Peck
SPSS
Andreas Völp
2007-04-04 15:01:15 UTC
Permalink
Post by JKPeck
compute strvar = replace(strvar, string(10, ib1),' ').
compute strvar = replace(strvar, string(12, ib1),' ').
Thanks a lot - this is exactly what I was looking for (although I must admit
that I still can't find this application of the STRING function anywhere in
the documentation ... but it works, so who cares?).

BTW: LF is ANSI character no. 13, not 12 ;-)

Best regards,
Andreas
JKPeck
2007-04-05 13:15:39 UTC
Permalink
Post by Andreas Völp
Post by JKPeck
compute strvar = replace(strvar, string(10, ib1),' ').
compute strvar = replace(strvar, string(12, ib1),' ').
Thanks a lot - this is exactly what I was looking for (although I must admit
that I still can't find this application of the STRING function anywhere in
the documentation ... but it works, so who cares?).
BTW: LF is ANSI character no. 13, not 12 ;-)
Best regards,
Andreas
The string function converts the numeric value given as the first
argument into a string using the format specified as the second
argument. ib stands for integer binary, so it works like the ord
function in some languages. And, yes, LF is 13 or x0D. Sorry about
that part.
Ray Koopman
2007-04-05 20:51:05 UTC
Permalink
Post by Andreas Völp
Post by JKPeck
compute strvar = replace(strvar, string(10, ib1),' ').
compute strvar = replace(strvar, string(12, ib1),' ').
Thanks a lot - this is exactly what I was looking for (although I must admit
that I still can't find this application of the STRING function anywhere in
the documentation ... but it works, so who cares?).
BTW: LF is ANSI character no. 13, not 12 ;-)
Best regards,
Andreas
The last time I looked, LF was 10 and CR was 13 ;-)
Chris Keran
2023-11-29 15:19:08 UTC
Permalink
Post by peter m sopp
- external editor (like Xemacs) (with export and re-import data - that's
the way I've solved some similar problems)
- python (should work I think - someone with an idea?)
Peter
Post by Andreas Völp
In SPSS 15, I have a data set (improted from MS Access via ODBC) with
several string variables some of which contain cariage return / line feed
(CR/LF) characters. In text-based reports these characters cause a
disruption of the column alignment, and therefore I would like to remove
them from the strings (by replacing CR/LF by a blank).
How can I do this? I couldn't find any way of specifying the CR/LF
characters so that I can use them in a COMPUTE command. Isn't there anything
like an ANSI or ASCII function that allows me to refer to these characters
by their character table numbers?
For clarity, this code deals with the cr and lf separately, Change
the second line to use '' as the replacement character if you want
only a single blank.
compute strvar = replace(strvar, string(10, ib1),' ').
compute strvar = replace(strvar, string(12, ib1),' ').
HTH,
Jon Peck
SPSS
Thank you, Jon, this worked for me too just now.

Loading...