Filter without space, what is wrong with this picture?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Filter without space, what is wrong with this picture?

Post by bogs » Sat Jan 26, 2019 5:43 pm

After a somewhat thorough search of this forum, I see lots of people recommending the use of "filter without space", but in a simple test for something I am doodling with at the moment, I still see a space in the variable I am using it on.

Open a message box, and put the following into the multi-line -

Code: Select all

put item 3 of the long date & "-" &  word 1 of item 2 of the long date into tmpArchive
// item 3 of the date has a space preceeding it...
filter tmpArchive without space
put chartoNum(character 1 of tmpArchive) 
The result line by line of this code is -
The message box wrote: the itemDelimiter is currently ","
Saturday, January 26, 2019 <- the long date...
2019-January <- item 3 of the long date which is supposed to have a space
Charcter 1 of the above line is 32 <- tells us that it is actually a space
After filter without space, charcter 1 of tmpArchive is 32
So the question is, why doesn't filter without space take that space out? What am I missing?

*Edit - so far, I have found this to be the case from 6.5.2 to 8.1.2, still going through previous versions.
Image

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Filter without space, what is wrong with this picture?

Post by Klaus » Sat Jan 26, 2019 5:51 pm

Hi bogs,

no idea why filter does not work here, maybe need to provide more info (a regex)?
In the meantime use:

Code: Select all

...
## filter tmpArchive without space
replace " " with "" in tmpArchive
put chartoNum(character 1 of tmpArchive) 
...
Best

Klaus

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Filter without space, what is wrong with this picture?

Post by bogs » Sat Jan 26, 2019 6:09 pm

Oh, I am sorry Klaus, I should have mentioned I already have a workaround done for this (I just deleted the first character in the variable). Your solution also works, as do many others I tried. Actually, I think yours may be the better of the two <scribbling it in> Image

The real problem here is, I believe that filter without space *should* have worked in this case, but obviously does not, and hasn't in fact worked in this case since at least 6.x. (still testing farther back, for all I know, this may be *inherited).

I wasn't able to find any bug reports about it either, so maybe my thinking is WAY off here, and this isn't how it is supposed to work :?

That is the main reason for the post, to find out if it *is* supposed to clear that space and should be reported as a bug, or if it is *not* supposed to clear that space, and what the reason that might be is, since it would seem to be contradictory to the way the language is used.

But thanks for the new line! :D

*Edit - apparently it is not inherited, as the last version of Mc doesn't actually include a filter 'without' option, only filter 'with' as far as I can tell :P
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Filter without space, what is wrong with this picture?

Post by [-hh] » Sat Jan 26, 2019 6:36 pm

This is not a bug.
filter uses either
  • a wildcard pattern
  • a regex pattern
filter string without space
is a wildcard pattern that finds and excludes all lines that are exactly space
What you are looking for is
filter string without space&"*" -- finds and excludes all lines starting with a space
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Filter without space, what is wrong with this picture?

Post by bogs » Sat Jan 26, 2019 11:02 pm

I actually tried that using this test code to see what would happen -

Code: Select all

// put the same item on lines 1 & 2 of tmpDate...
put item 3 of the long date & cr & item 3 of the long date into tmpDate
filter line 1 of tmpDate without space & "*"
put tmpDate
You weren't kidding when you said it would exclude the line if it started with a space, but that presents a different problem. The main question here is how to get rid of only the space, we want to keep the rest of the characters in the variable.

So, is there a way to filter out only a space in a given string ?

To give a better example, say you had "temp o rary" in a variable, and wanted to take out the 2 spaces in the middle using filter without.
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Filter without space, what is wrong with this picture?

Post by [-hh] » Sun Jan 27, 2019 2:21 am

This is not a job for filter that targets lines, items, keys or elements of a string/array, not chars.

To handle replacing chars or substrings of a string you could use replace.
Or for more differential searches you could use replaceText.
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Filter without space, what is wrong with this picture?

Post by bogs » Sun Jan 27, 2019 11:31 am

Ah, I see, so my mistake is the assumption that 'space' would fall under the 'item' or 'element' of a string category and be able to be filtered out of a line, where as what filter actually would do in that case is take the entire line out if a space is contained therein.

Thank you Hermann, I sure didn't get that from the dictionary definition.

As a side note, I was creating some variables that started with multiple lines recently, which were weened down to a single line. For some reason though, I always found an empty line at the end of the variable :roll:

I assume that same type of statement is what you would use to actually remove lines that are empty?

I.e. when going through the forums, I always see it suggested as

Code: Select all

filter string without empty

when the complete code *should be*

Code: Select all

filter string without empty & "*" 
which should blip any empty line in a variable?
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Filter without space, what is wrong with this picture?

Post by [-hh] » Sun Jan 27, 2019 2:05 pm

Hi bogs.

The wildcard char "*" stands for zero or more chars. So

Code: Select all

filter var without empty 
removes all empty lines from variable var, whereas

Code: Select all

filter string without empty&"*"
-- or equivalently:
filter var without "*"
removes ALL lines from variable var (results in an empty string).
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Filter without space, what is wrong with this picture?

Post by bogs » Sun Jan 27, 2019 2:34 pm

Got it, thanks!
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”