Question to gettoken with trim

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Question to gettoken with trim

Post 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.

admin
Site Admin
Posts: 66324
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Question to gettoken with trim

Post by admin »

Relax, I added trim(). Just forgot to add it to the change log. :mrgreen:

Code: Select all

text trim("  d  ");

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Question to gettoken with trim

Post 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: )

admin
Site Admin
Posts: 66324
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Question to gettoken with trim

Post by admin »

Yes, not yet.

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Question to gettoken with trim

Post 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:

admin
Site Admin
Posts: 66324
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Question to gettoken with trim

Post 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.

Twisten
Posts: 204
Joined: 27 Apr 2008 10:30

Re: Question to gettoken with trim

Post 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).

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Question to gettoken with trim

Post 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)?

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: Question to gettoken with trim

Post 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.

PeterH
Posts: 2827
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Question to gettoken with trim

Post 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:

admin
Site Admin
Posts: 66324
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Question to gettoken with trim

Post by admin »

I replaced the numbers by letters, but anything more appears overkill or simply "untrimmish".

stts
Posts: 18
Joined: 13 Apr 2006 06:33

Re: Question to gettoken with trim

Post 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.

highend
Posts: 14950
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Question to gettoken with trim

Post 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");
One of my scripts helped you out? Please donate via Paypal

stts
Posts: 18
Joined: 13 Apr 2006 06:33

Re: Question to gettoken with trim

Post 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. :)

Post Reply