VL-STRING-SEARCH is returning the correct result, but not the desired result.
I am looking for the shortest method to find if a path exists in a string by the exact value provided.
I first check to see if the path is currently set correctly.
(if (not (vl-string-search (strcase "C:\\Autodesk\\Standards\\Template\\") (strcase (getenv "TemplatePath")))) ...
If it is not, then I set is to the correct path
... (setenv "TemplatePath" "C:\\Autodesk\\Standards\\Template"))
The environment path is currently set to "C:\\Autodesk\\Standards\\Template\\2008". Which is not what I want the path to be.
But since the search string does exist in the path, VL-STRING-SEARCH does find the string and says it exists and therefore the path is not changed.
I could just set the path without the check, but its not what I wish to do.
Thanks.
Solved! Go to Solution.
Solved by pbejse. Go to Solution.
Hi,
I'm not sure to understand, but, why not simply force the path to the value you need?
Gaston Nunez
@hgasty1001 wrote:
Hi,
I'm not sure to understand, but, why not simply force the path to the value you need?
Gaston Nunez
The OP did say:
I could just set the path without the check, but its not what I wish to do. <--- OP's wish in this case is indeed to check first.
As an aside: vl-string-search is a pattern search, so in your case "pattern" found will evaluate to T . I would use use eq function instead.
HTH
@pbejse wrote:
As an aside: vl-string-search is a pattern search, so in your case "pattern" found will evaluate to T . I would use use eq function instead.
Another aside: this brought out yet another difference between AutoLISP and other Lisp languages.
In Common Lisp and Emacs Lisp, (eq "text" "text") returns nil, in AutoLISP T.
This is not important while working with AutoCAD, but might confuse you if you ever happen to work with the other systems or read general lisp books to learn.
--
@martti.halminen wrote:
@pbejse wrote:As an aside: vl-string-search is a pattern search, so in your case "pattern" found will evaluate to T . I would use use eq function instead.
Another aside: this brought out yet another difference between AutoLISP and other Lisp languages.
In Common Lisp and Emacs Lisp, (eq "text" "text") returns nil, in AutoLISP T.
--
I did not know that. Thank you for the info marti,
Cheers
@martti.halminen wrote:
@pbejse wrote:As an aside: vl-string-search is a pattern search, so in your case "pattern" found will evaluate to T . I would use use eq function instead.
.... another difference between AutoLISP and other Lisp languages.
In Common Lisp and Emacs Lisp, (eq "text" "text") returns nil, in AutoLISP T.
...
You can use the (=) function instead, which works with text strings [case-sensitive] as well as numerical values. [But I couldn't say whether it has the same difference as (eq) between AutoLISP and regular Lisp.]
Ah. Yes. Don't know why I didn't think of that.
I guess because I wrote that line when I was adding paths to the Support File Search Path where there are many paths instead of just matching one path. Then I did that bad thing of copy and paste. More errors show up from copy and paste.
Thanks.
@Kent1Cooper wrote:You can use the (=) function instead, which works with text strings [case-sensitive] as well as numerical values. [But I couldn't say whether it has the same difference as (eq) between AutoLISP and regular Lisp.]
In Common Lisp = only works on numbers, raises an error for anything else. This is not so bad, you'll notice the difference immediately. The eq difference is more sneaky, as it will accept anything, only the results differ.
--