Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

vl-string-search not returning desired result

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
dvertz
842 Views, 7 Replies

vl-string-search not returning desired result

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.

Civil 3D 2022,
Windows 10 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


7 REPLIES 7
Message 2 of 8
hgasty1001
in reply to: dvertz

Hi,

 

I'm not sure to understand, but, why not simply force the path to the value  you need?

 

Gaston Nunez

 

 

Message 3 of 8
pbejse
in reply to: hgasty1001


@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

Message 4 of 8
martti.halminen
in reply to: pbejse


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

 

--

Message 5 of 8
pbejse
in reply to: martti.halminen


@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  beer.gif

Message 6 of 8


@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.]

Kent Cooper, AIA
Message 7 of 8
dvertz
in reply to: pbejse

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.

Civil 3D 2022,
Windows 10 Pro, x64, Nvidia Quadro P1000
Intel Core i9-11900k; 3.50GHz, 32 GB RAM, 500GB WD BLACK M.2


Message 8 of 8


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

 

--

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost