Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to remove CR/LF characters from a string

251 views
Skip to first unread message

Andreas Völp

unread,
Apr 4, 2007, 4:32:39 AM4/4/07
to
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

unread,
Apr 4, 2007, 5:52:16 AM4/4/07
to
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

Andreas Völp schrieb:

JKPeck

unread,
Apr 4, 2007, 8:14:32 AM4/4/07
to

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

unread,
Apr 4, 2007, 11:01:15 AM4/4/07
to
> 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

unread,
Apr 5, 2007, 9:15:39 AM4/5/07
to


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

unread,
Apr 5, 2007, 4:51:05 PM4/5/07
to

The last time I looked, LF was 10 and CR was 13 ;-)

Chris Keran

unread,
Nov 29, 2023, 10:19:10 AM11/29/23
to
Thank you, Jon, this worked for me too just now.
0 new messages