Page 1 of 1

Question to gettoken with trim

Posted: 23 Mar 2012 11:13
by PeterH

Code: Select all

v10.90.0202 - 2012-03-22 10:33
    + SC gettoken enhanced: Now you can trim the returned string using a
      new parameter "format":
      Syntax: gettoken(string, [index=1], [separator=" "], [format])
        format:   Switches for the desired formatting. Can be freely
                  combined in any order.
          t = trim returned string (crop leading and trailing spaces)
Sorry: isn't this a bit ineffective?

Instead of creating a function trim(string, character=" ", position=both) allowing the above functionality by
trim(gettoken(string, index, separator))
and adding many more abilities, together with gettoken as well as many other types of usage, (for example with foreach, with getkey, and others,) you restrict this trim to only be used with/inside gettoken, and to only strip spaces left and right.

I'm a bit puzzled.

Re: Question to gettoken with trim

Posted: 23 Mar 2012 17:41
by admin
Relax, I added trim(). Just forgot to add it to the change log. :mrgreen:

Code: Select all

text trim("  d  ");

Re: Question to gettoken with trim

Posted: 24 Mar 2012 01:12
by PeterH
admin wrote:Relax, I added trim(). Just forgot to add it to the change log. :mrgreen:

Code: Select all

text trim("  d  ");
This man ... :roll: :lol:

No complaint, just a question: if I guess it right it only can trim spaces?
(As I see no operand to specify the character to trim :whistle: )

Re: Question to gettoken with trim

Posted: 24 Mar 2012 10:00
by admin
Yes, not yet.

Re: Question to gettoken with trim

Posted: 24 Mar 2012 11:16
by PeterH
admin wrote:Yes, not yet.
If, somewhen, you might expand it, I would :whistle: remind you of a possible 3rd operand leading, trailing, or both, with both as default.

But I wouldn't be surprised, if you did it allready :shock:

Re: Question to gettoken with trim

Posted: 24 Mar 2012 11:53
by admin
PeterH wrote:
admin wrote:Yes, not yet.
If, somewhen, you might expand it, I would :whistle: remind you of a possible 3rd operand leading, trailing, or both, with both as default.

But I wouldn't be surprised, if you did it allready :shock:
Not yet, but I like it. ... Now I did it.

Re: Question to gettoken with trim

Posted: 24 Mar 2012 18:52
by Twisten
Oh well ... in that case :whistle: how about a special settings for whitespace characters horizontal (tab space) and vertical (tab CR LF FF NEL).

Re: Question to gettoken with trim

Posted: 24 Mar 2012 18:53
by Stefan
admin wrote:Not yet, but I like it. ... Now I did it.
http://www.xyplorer.com/xyfc/viewtopic. ... 450#p71450

But why with numbers 1,2,3 as mode parameter? Why not simple L,R,B instead (or best additionally)?

Re: Question to gettoken with trim

Posted: 24 Mar 2012 22:19
by neutrox
I see usefulness on this if i could trim a string:

a. from a given string onwards or backwards up to the end or down to the start of its original line (or both)

b. same as above but up to a certain limit of characters

c. same as 'b' but able to state wildcards or explicit charlists as limits

d. inserting a replacement for the trimmed strings

more of a blind erasing function instead of trimming known characters.

Re: Question to gettoken with trim

Posted: 25 Mar 2012 11:53
by PeterH
neutrox wrote:I see usefulness on this if i could trim a string:

a. from a given string onwards or backwards up to the end or down to the start of its original line (or both)

b. same as above but up to a certain limit of characters

c. same as 'b' but able to state wildcards or explicit charlists as limits

d. inserting a replacement for the trimmed strings

more of a blind erasing function instead of trimming known characters.
You talk about trim()?

d. says you talk about replace()
and the very last line says you talk about erase()

Sure - they could be helpful, too.

But you say the current trim is not useful?
Strange...

@Don: quite some function in it that I didn't expect :D
(Especially the generic versions...)
I need (some time) to digest that. :roll:

But thanks: it surely will be helpful, at least for me! :whistle:

Re: Question to gettoken with trim

Posted: 26 Mar 2012 10:51
by admin
I replaced the numbers by letters, but anything more appears overkill or simply "untrimmish".

Re: Question to gettoken with trim

Posted: 23 Apr 2015 11:18
by stts
Is there a way to trim the last 4 characters off the file name strings? Folderreport returns filenames as strings and I want to cut off the period/extension from the end of the string. All I want is the file name base as a string.

Re: Question to gettoken with trim

Posted: 23 Apr 2015 11:34
by highend
Trim() isn't what you're looking for.

If you really only have the file name there is

Code: Select all

getpathcomponent("<your file name without path>", "base");
to do this...

Otherwise (with full path) use:

Code: Select all

regexreplace("<your file name with path>", "(.*)(\.[^.]+$)", "$1");

Re: Question to gettoken with trim

Posted: 23 Apr 2015 12:10
by stts
Thank you thank you. The second code worked perfectly. It would have been a pain for me to figure out all those little switches. :)