How to remove \n from the text field

Discussions about editing and cleaning data
Post Reply
khurshid.arshad
Posts: 606
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

How to remove \n from the text field

Post by khurshid.arshad »

Dear Team;

I want to remove "\n" from the text field through batch editing. The data file is in csdb format.
Please advice on how to resolve this issue.

thanks.
a.
Gregory Martin
Posts: 1845
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: How to remove \n from the text field

Post by Gregory Martin »

If you're using CSPro 8.0+, you'd simply do:
STRING_FIELD = replace(STRING_FIELD, "\n", "");
khurshid.arshad
Posts: 606
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: How to remove \n from the text field

Post by khurshid.arshad »

Dear Gregory;

I am using this in a batch file. When i run the application, it removes all informtion from the fields starting from the newline character ("\n") onward.

I am using cspro 7.7.

PROC RECOM_PSYCHOLOGIST1


Preproc
mystring =RECOM_PSYCHOLOGIST1;

mystring = replace(mystring, '\n', ' ');


RECOM_PSYCHOLOGIST1=mystring;
Thanks.
a.
khurshid.arshad
Posts: 606
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: How to remove \n from the text field

Post by khurshid.arshad »

One more thing:
After getting the data in csdb format using 7.7, I am using 8.0.1 to export the data from csdb to SPSS without using the replace function. In this case the new line character("\n") automatically replaced by a question mark(?), and all the data is exported without any issue.

thanks.
a.
Gregory Martin
Posts: 1845
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: How to remove \n from the text field

Post by Gregory Martin »

Escape sequences like \n are only supported using the logic version introduced in CSPro 8.0. See more here:

https://www.csprousers.org/help/CSPro/s ... erals.html

So if you're trying to replace "\n" using the old logic version, that string is not actually a newline character, but is instead a backslash character and n ("\\n" in the new logic version).

Basically if you want to manipulate any string with newlines, you'll have to use the new logic version.

You can read more about newlines here: https://www.csprousers.org/help/CSPro/n ... dling.html
khurshid.arshad
Posts: 606
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: How to remove \n from the text field

Post by khurshid.arshad »

Thank you.
A.
Post Reply