Code Red > AutoLISP (Vanilla / Visual)
I'm not understanding what is going on here.
Eddie D.:
I'm getting an unexpected result from vl-string-left-trim that I don't understand.
This works is as expected:
(vl-string-left-trim "PREFIX: " "PREFIX: ABCDEF")
Result: "ABCDEF"
This result has me confused:
(vl-string-left-trim "PREFIX: " "PREFIX: FEDCBA")
Result: "DCBA"
I get a similar unexpected result if the beginning of the expected return string begins with E, F, I, P, R, and X.
What am I missing here?
efernal:
Command: (vl-string-left-trim "PREFIX: " "PREFIX: FEDCBA")
"DCBA"
same here...
efernal:
vl-string-trim
Removes the specified characters from the beginning and end of a string
(vl-string-trim char-set str)
Arguments
char-set
A string listing the characters to be removed.
str
The string to be trimmed of char-set.
Return Values
The value of str, after any characters have been trimmed.
Examples
_$ (vl-string-trim " \t\n" " \t\n STR \n\t ")
"STR"
_$ (vl-string-trim "this is junk" "this is junk Don't call this
junk! this is junk")
"Don't call this junk!"
_$ (vl-string-trim " " " Leave me alone ")
"Leave me alone"
MP:
To add to what efernal posted ...
There's a number of ways to achieve (what I believe is) your intended result.
Observe what results from the following code snips which represent one of several ways:
(setq text "PREFIX: FEDCBA")
(if (< 0 (setq i (vl-string-mismatch "PREFIX: " text)))
(substr text (1+ i))
text
)
>> "FEDCBA"
(setq text "prefix: fedcba")
(if (< 0 (setq i (vl-string-mismatch "PREFIX: " text)))
(substr text (1+ i))
text
)
>> "prefix: fedcba"
(setq text "prefix: fedcba")
(if (< 0 (setq i (vl-string-mismatch "PREFIX: " (strcase text))))
(substr text (1+ i))
text
)
>> "fedcba"
You may wish to review the documentation for these functions:
vl-string-trim:
http://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-FF1DA441-C9D8-4C99-BC6E-B2A72B562389
vl-string-subst:
http://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-D8EE91DC-D4DB-43E0-9AFE-5FA166C0896D
vl-string-mismatch:
http://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-D1EA6F47-146E-44BC-BBCA-40B7A874C0B8
etc.
Cheers.
Eddie D.:
Thanks for the replies, guys!
efernal, I get the same results with vl-string-trim.
MP, thanks for the examples, but I still don't understand why I get the results I'm getting with vl-string-trim/vl-string-left-trim.
Any ideas?
Navigation
[0] Message Index
[#] Next page
Go to full version