grandhougday Posted February 22, 2012 Posted February 22, 2012 I want to write a lisp that read a text from model space and replace some characters in it. for this work i iterate each character and take Ascii code of each one, then in if-else do replacement. in some chars it get wrong answers. for example in character "Þ" (latin capital letter thorn)(Ascii code:222 or Hex=\U+00DE). both (vl-string-elt "Þ" 0) and (Ascii "Þ") commands give me 92 as a resault of it ascii code i use doslib, but same problem exist. does any one know what's the problem? Quote
Lee Mac Posted February 22, 2012 Posted February 22, 2012 Are you sure you are testing it correctly? For me: _$ (ascii "Þ") 222 Quote
grandhougday Posted February 22, 2012 Author Posted February 22, 2012 may be something strange is wrong with me. i tried in XP SP3, and win7(64), with Acad2009, Acad2012 and 2011 All give me : Command: (ascii "Þ") 92 Quote
Lee Mac Posted February 22, 2012 Posted February 22, 2012 What happens if you test it through the VLIDE Console? Quote
grandhougday Posted February 22, 2012 Author Posted February 22, 2012 I'm really confused with this: _$ Command: (ascii "Þ") 92 nil 222 92 _$ (Ascii "Þ") 222 _$ (Ascii "Þ") 222 _$ (Ascii "Þ") 222 in the first run VLIDE was also confused and in later run it got the true answer. When I paste from charmap, char turn into question mark and return equivalent ascii that is 63 _$ (ascii "?") 63 and still in command prompt it say's 92. I have a second language installed. is it the cause? Quote
Lee Mac Posted February 22, 2012 Posted February 22, 2012 Firstly, the capital in (Ascii) will make no difference since LISP isn't case-sensitive. Now: _$ Command: (ascii "Þ") 92 nil 222 92 This result is because you have copied 'Command:' to the console as well, which is interpreted as a null symbol: _$ Command: (ascii "Þ") nil 222 _$ Command: nil Though, I'm not sure where the ASCII 92 (backslash "\") codes are coming from. As for: _$ (ascii "?") 63 63 is simply the ASCII code for the question mark. LISP can only process ASCII characters, so any Unicode characters copied into the console will be converted to question marks. Quote
grandhougday Posted February 22, 2012 Author Posted February 22, 2012 Is it give 222 also in your command prompt? Quote
grandhougday Posted February 22, 2012 Author Posted February 22, 2012 in cases that i face with these kind of problem (i mean this char and some other char) in the following code txt1 and txt2 give different answers: (setq item (ssname sset i)) (setq ed (entget item)) (setq VlObj (vlax-ename->vla-object item)) (setq txt2 (vla-get-textstring VlObj)) (setq txt1 (cdr(assoc 1 ed))) Quote
Lee Mac Posted February 22, 2012 Posted February 22, 2012 Yes, there is a known bug wherein Extended ASCII and Unicode symbols will be replaced with question marks '?' when the text content is retrieved using the TextString property of the VLA-Object. When the Text object contains such characters, always use the DXF Group codes. Quote
grandhougday Posted February 22, 2012 Author Posted February 22, 2012 I think i should find some way to extract correct chars. And Thanks for your professional comments. Quote
grandhougday Posted February 23, 2012 Author Posted February 23, 2012 I found out what is the meaning of result of (vl-string-elt). in command prompt i get this answer: Command: (vl-string-elt "Þ" 0) 92 Command: (vl-string-elt "Þ" 1) 85 Command: (vl-string-elt "Þ" 2) 43 Command: (vl-string-elt "Þ" 3) 48 Command: (vl-string-elt "Þ" 4) 48 Command: (vl-string-elt "Þ" 5) 68 Command: (vl-string-elt "Þ" 6) 69 that means :\U+00DE that means "222" can anyone know why it does like this? and how can get right answer? Quote
Lee Mac Posted February 23, 2012 Posted February 23, 2012 What happens if you use: (vl-string->list "Þ") Quote
grandhougday Posted February 23, 2012 Author Posted February 23, 2012 This is the result: Command: (vl-string->list "Þ") (92 85 43 48 48 68 69) Quote
Lee Mac Posted February 23, 2012 Posted February 23, 2012 OK, so from that, I'm guessing that this: (vl-list->string (vl-string->list "Þ") Will return: "\U+00DE" With this in mind we can convert the Hexadecimal part (00DE) to a Decimal representation: (defun _ascii ( ch ) (_HexList->Decimal (reverse (cdddr (vl-string->list ch)))) ) (defun _HexList->Decimal ( lst ) (if lst (+ (* 16 (_HexList->Decimal (cdr lst))) (if (< (car lst) 65) (- (car lst) 48) (- (car lst) 55) ) ) 0 ) ) _$ (_ascii "Þ") 222 Quote
grandhougday Posted February 23, 2012 Author Posted February 23, 2012 I'll Try it as soon as i can. Thanks a lot. Quote
Ahankhah Posted February 28, 2012 Posted February 28, 2012 (edited) Lee, let me edit your excellent code so the internal "ascii" function can be replaced with the new one: [size=3][font=Calibri](defun _ascii (ch / ret)[/font][/size] [size=3][font=Calibri] (if (zerop (setq ret (_HexList->Decimal (reverse (cdddr (vl-string->list ch))))))[/font][/size] [size=3][font=Calibri] (ascii ch)[/font][/size] [size=3][font=Calibri] ret[/font][/size] [size=3][font=Calibri] ) [/font][/size] [size=3][font=Calibri])[/font][/size] [size=3][font=Calibri](defun _HexList->Decimal (lst)[/font][/size] [size=3][font=Calibri] (if lst[/font][/size] [size=3][font=Calibri] (+ (* 16 (_HexList->Decimal (cdr lst)))[/font][/size] [size=3][font=Calibri] (if (< (car lst) 65)[/font][/size] [size=3][font=Calibri] (- (car lst) 48)[/font][/size] [size=3][font=Calibri] (- (car lst) 55)[/font][/size] [size=3][font=Calibri] )[/font][/size] [size=3][font=Calibri] )[/font][/size] [size=3][font=Calibri] 0[/font][/size] [size=3][font=Calibri] )[/font][/size] [font=Calibri][size=3])[/size][/font] Edited February 28, 2012 by Ahankhah Quote
marko_ribar Posted February 28, 2012 Posted February 28, 2012 This is some sort of wrong result - on my comp it's correct : Command: (vl-string->list "Þ") (222) M.R. Quote
Ahankhah Posted February 28, 2012 Posted February 28, 2012 This is some sort of wrong result - on my comp it's correct : Command: (vl-string->list "Þ") (222) M.R. But on my computer: in AutoCAD command line: Command: (vl-string->list "Þ") (92 85 43 48 48 68 69) and in Vlide console: _$ (vl-string->list "?") (63) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.