dbTalk Databases Forums  

Trim()

comp.databases.filemaker comp.databases.filemaker


Discuss Trim() in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
42
 
Posts: n/a

Default Re: Trim() - 07-08-2005 , 09:28 PM






In article <11cuba352e7cff (AT) corp (DOT) supernews.com>,
howard (AT) antispahm (DOT) fmprosolutions.com says...
to have you here, as you seem very knowledgable about things. As
Quote:
for John Weinshel, I know he lurks here now and then, and he is active
on some more developer-oriented other lists.
Glad to hear he's still around. I'm suddenly curious about these other
more developer-oriented lists... sounds like good reading material.

Of course I'm not FSA if that's a pre-req... I have solid enough work
that I don't need it to generate revenue, and at the time I took (and
passed) the test (devcon in palm desert [year??]) it really felt like
more of a business development vehicle than a technical resource
vehicle, so i never signed up. I'd have let it lapse anyways the last
few years though regardless.

Quote:
What part of the world are
you in (feel free to back-channel me if you'd like)?
Vancouuver, Canada


Reply With Quote
  #12  
Old   
Helpful Harry
 
Posts: n/a

Default Re: Trim() - 07-08-2005 , 11:10 PM







Here we go - a quick Google search turns up a solution. )

Debi Fuchs has already solved this problem over on the Cleveland
Consulting support (www.clevelandconsulting.com) forums for those using
FileMaker 7:


// Supertrim( text )
// ======================================
// Remove any leading and trailing whitespace from a string of text

Let(
* * [
* * * * // Determine result of removing ALL whitespace.
* * * * t2 =
* * * * Substitute(
* * * * * * text;
* * * * * * [ "*"; "" ];
* * * * * * [ " "; "" ];
* * * * * * [ "* *"; "" ];
* * * * * * [ "¶"; "" ]
* * * * );

* * * * // Find position of first non-ws character in original text.
* * * * first_char = Position( text; Left( t2; 1 ); 0; 1 );

* * * * // Find position of last non-ws character in original text.
* * * * last_char =
* * * * Position( text; Right( t2; 1 ); Length( text ); -1 )
* * ];

* * // If any non-whitespace characters exist, then return
* * // appropriate substring of original text.
* * Case(
* * * * first_char;
* * * * Middle( text; first_char; last_char - first_char + 1 )
* * )
)


It looks good to me, but I don't have FileMaker 7 to test it on (of
course it could be squashed down into a single calculation for use on
older versions too).

Since it doesn't use the "Words" versions of Left and Middle functions
it should handle any trailing punctuation symbols correctly as well.


Note:
Unfortunately, thanks to code-mangling by text-based forums, I'm not
exactly sure what all the whitespace characters the Substitute function
at the beginning is meant to be removing.

Substitute(
* text;
* [ "*"; "" ]; Spaces
* [ " "; "" ]; ???
* [ "* *"; "" ]; Tabs
* [ "¶"; "" ] Carriage Returns
);

Obviously this can easily be modified to remove whatever characters you
want it to anyway.




Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)

Reply With Quote
  #13  
Old   
ursus.kirk
 
Posts: n/a

Default Re: Trim() - 07-10-2005 , 06:16 AM



You wrote: > This is a bug,imo. FM3/4/5/6 did it correctly.

But I found: From the HelpFile of FM6 I copied the following.

Returns the supplied text, stripped of all leading and trailing spaces.
Tip Use Trim to remove unneeded spaces when you convert files from other
programs or systems that require a fixed number of characters per field, or
to remove spaces accidentally typed during data entry.

This supports what I seem to remember. Trim has never done anything else
then removing spaces.

Ursus



Reply With Quote
  #14  
Old   
Lee Smith
 
Posts: n/a

Default Re: Trim() - 07-10-2005 , 05:11 PM



in article 42d104da$0$82405$dbd43001 (AT) news (DOT) wanadoo.nl, ursus.kirk at
secret (AT) nowhere (DOT) com wrote on 7/10/05 4:16 AM:

Quote:
You wrote: > This is a bug,imo. FM3/4/5/6 did it correctly.

But I found: From the HelpFile of FM6 I copied the following.

Returns the supplied text, stripped of all leading and trailing spaces.
Tip Use Trim to remove unneeded spaces when you convert files from other
programs or systems that require a fixed number of characters per field, or
to remove spaces accidentally typed during data entry.

This supports what I seem to remember. Trim has never done anything else
then removing spaces.

Ursus


You are correct about the Trim, it is only for leading and trailing spaces.

In order to deal with multiple returns, you have to use a multiple
Substitute and the "¶" (paragraph symbol, AKA as the PILCROW), such as shown
in this formula posted by Bob Weaver on Oct 23, 2003, here:
http://www.fmforums.com/threads/show...6&Number=85271

which I'm quoting here:

Substitute(Substitute(Substitute(Substitute(InputT ext,
"¶¶¶¶¶¶¶","¶"),
"¶¶¶","¶"),
"¶¶","¶"),
"¶¶","¶")

This formula will convert from 2 to 41 contiguous ¶'s to a single ¶.



Reply With Quote
  #15  
Old   
ursus.kirk
 
Posts: n/a

Default Re: Trim() - 07-10-2005 , 05:46 PM



Lee

For FM7 this can be simplified into

Substitute(Inputtekst;
["¶¶¶¶¶¶¶","¶"];
["¶¶¶¶¶¶","¶"];
["¶¶¶¶¶","¶"];
["¶¶¶¶","¶"];
["¶¶¶","¶"];
["¶¶","¶"])

Ursus

Quote:
You are correct about the Trim, it is only for leading and trailing
spaces.

In order to deal with multiple returns, you have to use a multiple
Substitute and the "¶" (paragraph symbol, AKA as the PILCROW), such as
shown
in this formula posted by Bob Weaver on Oct 23, 2003, here:
http://www.fmforums.com/threads/show...6&Number=85271

which I'm quoting here:

Substitute(Substitute(Substitute(Substitute(InputT ext,
"¶¶¶¶¶¶¶","¶"),
"¶¶¶","¶"),
"¶¶","¶"),
"¶¶","¶")

This formula will convert from 2 to 41 contiguous ¶'s to a single ¶.



Reply With Quote
  #16  
Old   
Lee Smith
 
Posts: n/a

Default Re: Trim() - 07-10-2005 , 10:58 PM



in article 42d1a549$0$3471$dbd4d001 (AT) news (DOT) wanadoo.nl, ursus.kirk at
secret (AT) nowhere (DOT) com wrote on 7/10/05 3:46 PM:

Hi Ursus,

Thanks for pointing that out. I didn't know this had changed until about an
hour after I posted the other one. However, I also didn't pick up the
version of the 42 is using.

I'm so glad to see this improved, it has been a real PIA ganging the
substitutes in prior versions. Unfortunately, I'm still doing most of my
developing in v6 and earlier.

Lee

Quote:
Lee

For FM7 this can be simplified into

Substitute(Inputtekst;
["¶¶¶¶¶¶¶","¶"];
["¶¶¶¶¶¶","¶"];
["¶¶¶¶¶","¶"];
["¶¶¶¶","¶"];
["¶¶¶","¶"];
["¶¶","¶"])

Ursus

You are correct about the Trim, it is only for leading and trailing
spaces.

In order to deal with multiple returns, you have to use a multiple
Substitute and the "¶" (paragraph symbol, AKA as the PILCROW), such as
shown
in this formula posted by Bob Weaver on Oct 23, 2003, here:
http://www.fmforums.com/threads/show...6&Number=85271

which I'm quoting here:

Substitute(Substitute(Substitute(Substitute(InputT ext,
"¶¶¶¶¶¶¶","¶"),
"¶¶¶","¶"),
"¶¶","¶"),
"¶¶","¶")

This formula will convert from 2 to 41 contiguous ¶'s to a single ¶.




Reply With Quote
  #17  
Old   
42
 
Posts: n/a

Default Re: Trim() - 07-12-2005 , 12:09 PM



In article <slrndd7l06.pdp.t-use (AT) ID-685 (DOT) user.individual.de>, t-
use (AT) gmx (DOT) net says...
Quote:
On Mon, 11 Jul 2005 00:46:33 +0200, ursus.kirk wrote:
Lee

For FM7 this can be simplified into

Substitute(Inputtekst;
["¶¶¶¶¶¶¶","¶"];
["¶¶¶¶¶¶","¶"];
["¶¶¶¶¶","¶"];
["¶¶¶¶","¶"];
["¶¶¶","¶"];
["¶¶","¶"])

You could do it recursively. Apart from that, you might just use

Substitute(Inputtekst;
["¶¶","¶"];
["¶¶","¶"];
["¶¶","¶"];
["¶¶","¶"];
["¶¶","¶"];
["¶¶","¶"])

This would remove up to 64 <CR> together, since every command would
operate on two behind each other - and the next two behind each other,
dividing the number of returns by two with every command.

However, I'd prefer s( text, \r+, \r) - this would be a regular
expressions syntax: s/\r+/\r/g

Even simpler could be a supertrim function to cut off trailing and
leading " ", hard space cmd-" ", optional "_", tab and cr...
If we had regular expressions 90% of the parsing questions here would be
trivial.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.