Page 1 of 1
Filter without space, what is wrong with this picture?
Posted: Sat Jan 26, 2019 5:43 pm
by bogs
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.
Re: Filter without space, what is wrong with this picture?
Posted: Sat Jan 26, 2019 5:51 pm
by Klaus
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
Re: Filter without space, what is wrong with this picture?
Posted: Sat Jan 26, 2019 6:09 pm
by bogs
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>
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!
*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

Re: Filter without space, what is wrong with this picture?
Posted: Sat Jan 26, 2019 6:36 pm
by [-hh]
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
Re: Filter without space, what is wrong with this picture?
Posted: Sat Jan 26, 2019 11:02 pm
by bogs
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.
Re: Filter without space, what is wrong with this picture?
Posted: Sun Jan 27, 2019 2:21 am
by [-hh]
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.
Re: Filter without space, what is wrong with this picture?
Posted: Sun Jan 27, 2019 11:31 am
by bogs
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
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
when the complete code *should be*
which should blip any empty line in a variable?
Re: Filter without space, what is wrong with this picture?
Posted: Sun Jan 27, 2019 2:05 pm
by [-hh]
Hi bogs.
The wildcard char "*" stands for zero or more chars. So
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).
Re: Filter without space, what is wrong with this picture?
Posted: Sun Jan 27, 2019 2:34 pm
by bogs
Got it, thanks!