Moderators: Carlo Sans, jbouche
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Posted
Hi,

If written a function wich Itrim's a string:

( s s ) ITRIM gives (s s)

Here's the code:

/ITRIM {
/st1 exch def
/st2 st1 length string def

/p1 0 def
/teken 0 def
/tekv 32 def

% see if a character is <space>
st1 {
/teken exch def
teken 32 ne tekv 32 ne or {
st2 p1 teken put
/p1 p1 1 add def
} if

/tekv teken def
} forall

% see if last character is <space>
p1 0 gt {
st2 p1 1 sub get 32 eq {
/p1 p1 1 sub def
} if
} if

st2 0 p1 getinterval
} def

It seems to work perfectly.

Greetings RobertB
 
Posts: 4 | Registered: 02 February 2005Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
Nice code but that's already a VIPP function called BSTRIP so no need to re-invent the wheel :-)
 
Posts: 1769 | Location: Switzerland | Registered: 04 May 2001Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
No,

BSTRIP only remove spaces from the end and the beginning:

(<SPACE>a<SPACE><SPACE>a<SPACE> ) BSTRIP gives (a<SPACE><SPACE>a)
(<SPACE>a<SPACE><SPACE>a<SPACE> ) ITRIM gives (a<SPACE>a)

So it's very handy I think.

[This message has been edited by Robert Buster (edited 02-03-2005).]
 
Posts: 4 | Registered: 02 February 2005Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
No,

BSTRIP only removes spaces from the beginning & end of the string:
ITRIM also replace multiple spaces within the string with one:

(<SPACE>A<SPACE><SPACE><SPACE>A<SPACE> ) ITRIM gives (A<SPACE>A)

Greetings Robert
 
Posts: 4 | Registered: 02 February 2005Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
OK great.
To the forum: Does it make sense to integrate such a function into VIPP ?
Can you give some use cases where it may be useful ?
Thanks.
 
Posts: 1769 | Location: Switzerland | Registered: 04 May 2001Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
Yeah,

I think integration might be usefull. Imagine you have a name from 3 strings, then you do something like this:

($$TITLE. $$FNAME. $$LNAME.) VSUB SHL

If the field FNAME would be empty you get 2 spaces between TITLE and LNAME.
ITRIM solves this:

($$TITLE. $$FNAME. $$LNAME.) VSUB ITRIM SHL

You can use it for anything, includeing the cases where you used to use BSTRIP.

Greetings Robert
 
Posts: 4 | Registered: 02 February 2005Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
Hi

Did this ever get implemented?

This would also be hand if you could choose the character that you would like to trim.
 
Posts: 79 | Location: Stockton, UK | Registered: 14 November 2005Reply With QuoteEdit or Delete MessageReport This Post
Wim
Posted Hide Post
Hi

Did this ever get implemented?

I can't find any function that does this in 7.0

Regards,
Wim
 
Posts: 14 | Location: Brussels | Registered: 27 December 2006Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
It's called BTRIM and it has been there since VII 4.0 (end 2005). Documented in the readme and reference manual.
In addition the REPLACE transform (introduced in VII 6.0a) can also be handy to perform character replacement.
 
Posts: 1769 | Location: Switzerland | Registered: 04 May 2001Reply With QuoteEdit or Delete MessageReport This Post
Wim
Posted Hide Post
I mean the 'ITRIM' function BSTRIP only removes spaces before and at the end.

What to use in this case:
quote:

($$TITLE. $$FNAME. $$LNAME.) VSUB SHL

If the field FNAME would be empty you get 2 spaces between TITLE and LNAME.
ITRIM solves this:

($$TITLE. $$FNAME. $$LNAME.) VSUB ITRIM SHL
 
Posts: 14 | Location: Brussels | Registered: 27 December 2006Reply With QuoteEdit or Delete MessageReport This Post
Posted Hide Post
The final name of the function is BTRIM not ITRIM. Use

($$TITLE. $$FNAME. $$LNAME.) VSUB BTRIM SHL
 
Posts: 1769 | Location: Switzerland | Registered: 04 May 2001Reply With QuoteEdit or Delete MessageReport This Post
  Powered by Eve Community