Tabs and spaces

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Tabs and spaces

Deb Ploskonka

Hello,

 

I am matching two files on a string variable.  The strings are quite long (over 200 characters).  I’m having trouble matching as in one file, in the middle of a few of the strings there is a tab and a space, and in the corresponding string in the other file it’s two spaces.  I’ve been searching this list to see if there’s a simple way to replace it or even compress all the spaces of any kind out in order to match.  Suggestions are most welcome!

 

Thank you.

Deb

Reply | Threaded
Open this post in threaded view
|

Re: Tabs and spaces

Mario Giesel
I think the command goes like 
COMPUTE new = REPLACE(old," ","").
You can try with the tab character as well.

Good luck,
 Mario


=========

Am 30.04.2012 um 02:42 schrieb Deb Ploskonka <[hidden email]>:

Hello,

 

I am matching two files on a string variable.  The strings are quite long (over 200 characters).  I’m having trouble matching as in one file, in the middle of a few of the strings there is a tab and a space, and in the corresponding string in the other file it’s two spaces.  I’ve been searching this list to see if there’s a simple way to replace it or even compress all the spaces of any kind out in order to match.  Suggestions are most welcome!

 

Thank you.

Deb

Mario Giesel
Munich, Germany
Reply | Threaded
Open this post in threaded view
|

Re: Tabs and spaces

David Marso
Administrator
In reply to this post by Deb Ploskonka
This should be helpful ;-)
--
data list free / x .
begin data
1
end data.

numeric tb (PIB1).
COMPUTE tb=9.

STRING stb (A1).
COMPUTE stb=STRING(tb,PIB1).

string junk (A10).
LOOP #=1 TO 10.
COMPUTE SUBSTR(junk,#,1)=stb.
END LOOP.

STRING CPy (A10).
COMPUTE Cpy=JUNK.
LOOP #=1 TO 10.
IF SUBSTR(Cpy,#,1)=stb SUBSTR(Cpy,#,1)="@".
END LOOP.
LIST.
Deb Ploskonka wrote
Hello,

I am matching two files on a string variable.  The strings are quite long (over 200 characters).  I'm having trouble matching as in one file, in the middle of a few of the strings there is a tab and a space, and in the corresponding string in the other file it's two spaces.  I've been searching this list to see if there's a simple way to replace it or even compress all the spaces of any kind out in order to match.  Suggestions are most welcome!

Thank you.
Deb
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Tabs and spaces

David Marso
Administrator
Drum roll....(using previous post for context)
IF ANY(SUBSTR(Cpy,#,1),stb," ") SUBSTR(Cpy,#,1)="".
-----

David Marso wrote
This should be helpful ;-)
--
data list free / x .
begin data
1
end data.

numeric tb (PIB1).
COMPUTE tb=9.

STRING stb (A1).
COMPUTE stb=STRING(tb,PIB1).

string junk (A10).
LOOP #=1 TO 10.
COMPUTE SUBSTR(junk,#,1)=stb.
END LOOP.

STRING CPy (A10).
COMPUTE Cpy=JUNK.
LOOP #=1 TO 10.
IF SUBSTR(Cpy,#,1)=stb SUBSTR(Cpy,#,1)="@".
END LOOP.
LIST.
Deb Ploskonka wrote
Hello,

I am matching two files on a string variable.  The strings are quite long (over 200 characters).  I'm having trouble matching as in one file, in the middle of a few of the strings there is a tab and a space, and in the corresponding string in the other file it's two spaces.  I've been searching this list to see if there's a simple way to replace it or even compress all the spaces of any kind out in order to match.  Suggestions are most welcome!

Thank you.
Deb
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Tabs and spaces

Jon K Peck
In reply to this post by Deb Ploskonka
Specifying a tab character is a little tricky.  Try this code to turn all tabs into blanks.
compute strvar = replace(strvar, string(09, pib1),' ').

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Deb Ploskonka <[hidden email]>
To:        [hidden email]
Date:        04/29/2012 06:46 PM
Subject:        [SPSSX-L] Tabs and spaces
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hello,
 
I am matching two files on a string variable.  The strings are quite long (over 200 characters).  I’m having trouble matching as in one file, in the middle of a few of the strings there is a tab and a space, and in the corresponding string in the other file it’s two spaces.  I’ve been searching this list to see if there’s a simple way to replace it or even compress all the spaces of any kind out in order to match.  Suggestions are most welcome!
 
Thank you.
Deb
Reply | Threaded
Open this post in threaded view
|

Re: Tabs and spaces

Deb Ploskonka
In reply to this post by Deb Ploskonka

Hi,

 

Just to follow up with the solution … I finally identified the reason none of my attempts nor the kind offers to help with the tabs were working was it was not a tab, it was Hex A0 (a non-breaking space), which I was also kindly informed was decimal 160.  This worked:

 

compute strvar = replace(strvar, string(160, pib1),' ').

 

Thank you!

Deb

 

From: Deb Ploskonka
Sent: Sunday, April 29, 2012 7:43 PM
To: '[hidden email]'
Subject: Tabs and spaces

 

Hello,

 

I am matching two files on a string variable.  The strings are quite long (over 200 characters).  I’m having trouble matching as in one file, in the middle of a few of the strings there is a tab and a space, and in the corresponding string in the other file it’s two spaces.  I’ve been searching this list to see if there’s a simple way to replace it or even compress all the spaces of any kind out in order to match.  Suggestions are most welcome!

 

Thank you.

Deb