Search a string for \ character

Search a string for \ character

jwright1962
Advocate Advocate
1,425 Views
4 Replies
Message 1 of 5

Search a string for \ character

jwright1962
Advocate
Advocate

suppose i have some code:

 

setq somestring "45'-4\" 

(vl-string-position (ascii "\") somestring)

 

the vl-string-position as shown doesn't work.   wondering how to search a string for \  ?  

 

0 Likes
1,426 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

I don't have AutoCAD on this computer, but I would think one of these should work:

  (ascii "\\")

  (ascii "`\")

 

EDIT:  But the only reason for the \ in:

  (setq somestring "45'-4\")

would be as an escape character for the inches mark, so it isn't read as the end of the string, in which case it should be:

  (setq somestring "45'-4\"")

with the first " being the inches mark, and the second " ending the string.  But then I believe the \" together are considered one character.  And it may not be possible to find the "position" of the \ alone, with either of my suggestions.

Kent Cooper, AIA
0 Likes
Message 3 of 5

hak_vz
Advisor
Advisor

 

(setq somestring "45'-4\\")
(vl-string-position (ascii "\\") somestring)-> 5

\ symbol is an interupt that is used to let say add new line "\n" or new paragraph "\p"

To present "\" you have to double it.

 (setq somestring "45'-4\")

This will produce an error since parser will keep looking for right parenthesis.  (ascii "''\") won't work.

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 5

Sea-Haven
Mentor
Mentor

Also (vl-string-position 92 somestring)

 

To find number type (ascii (getstring)) then say \

0 Likes
Message 5 of 5

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

...  But the only reason for the \ in:

  (setq somestring "45'-4\")

would be as an escape character for the inches mark, so it isn't read as the end of the string, in which case it should be:

  (setq somestring "45'-4\"")

... the \" together are considered one character.  And it may not be possible to find the "position" of the \ alone, with either of my suggestions.


If that's the situation, now that I'm on an AutoCAD computer, I can confirm:

    (setq somestring "45'-4\"")

returns the feet-and-inches string:
    "45'-4\""
which is what the entity data entry looks like for a Text object with that feet-and-inches content:

Kent1Cooper_0-1617622533353.png

Then:

    (vl-string-position (ascii "\"") somestring)
returns the position of the inches mark:

    5
But the backslash does not exist as a character on its own in the string, but only as "part of" the inches mark character.  This:

    (ascii "\\")

is the right way to get the character code for a backslash:

    92

but:

    (vl-string-position (ascii "\\") somestring)

returns
    nil

Kent Cooper, AIA
0 Likes