Ahankhah Posted March 2, 2016 Share Posted March 2, 2016 Hi all, I have written a simple routine to convert "Unicode"s to equivalent "character"s It is as following: (defun MT:Conv:Unichar->Char ;added: 94/12/12 (%unichar% / *ret*) (command "_.TEXT" '(0 0) "0.3" "0" %unichar%) (setq *ret* (cdr (assoc 1 (entget (entlast))))) (entdel (entlast)) *ret* ) Example: (MT:Conv:Unichar->Char "\\U+0647") -- returns --> "ه" Is there any way to define a function to do the reverse? I mean, it gets "character" as arguments and returns equivalent "Unicode"? I appreciate any help or suggestions. Quote Link to comment Share on other sites More sharing options...
honglog Posted July 3, 2017 Share Posted July 3, 2017 Hi, what if you replace *ret* with (vl-string->list *ret*)? does it return (92 85 43 48 54 52 55) ? 1 Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted July 3, 2017 Share Posted July 3, 2017 @Ahankhah: The function MT:CONV:UNICHAR->CHAR doesn't do much... In a roundabout way it merely returns the input string. (setq a (MT:CONV:UNICHAR->CHAR "\U+0647")) (setq b "\U+0647") (= a b) => T My suggestion for your request: ; (String_To_UniCode "ABC") => "\\U+0041\\U+0042\\U+0043" (defun String_To_UniCode (str) (apply 'strcat (mapcar '(lambda (int / hex) (setq hex (KGA_Math_Dec_To_Hex int)) (repeat (- 4 (strlen hex)) (setq hex (strcat "0" hex)) ) (strcat "\\U+" hex) ) (vl-string->list str) ) ) ) (defun KGA_Math_Dec_To_Base (int base / lst rest) (if (zerop int) "0" (progn (while (> int 0) (setq rest (rem int base) lst (cons (+ rest (if (<= rest 9) 48 55)) lst) int (/ int base) ) ) (vl-list->string lst) ) ) ) ; (KGA_Math_Dec_To_Hex 2147483647) => "7FFFFFFF" ; (KGA_Math_Dec_To_Hex 14285) => "37CD" ; (KGA_Math_Dec_To_Hex 0) => "0" (defun KGA_Math_Dec_To_Hex (int) (KGA_Math_Dec_To_Base int 16) ) 1 Quote Link to comment Share on other sites More sharing options...
honglog Posted July 4, 2017 Share Posted July 4, 2017 (vl-string->list "ABC") does return (65 66 67). For ASCII characters, it works. What about international characters? (vl-string->list "ه") returns (92 85 43 48 54 52 55), which turns out to be \U+0647 And dismayingly, in my dwgcodepage ANSI_936, (vl-string->list "啊") returns (176 161) rather than its unicode which should be \U+554A 1 Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted July 4, 2017 Share Posted July 4, 2017 @honglog: It seems that BricsCAD (the program I use) and AutoCAD have a different implementation of vl-string->list and perhaps also of the ascii function. Some tests with BricsCAD: (setq a "\U+0647") (ascii a) => 1607 (vl-string->list a) => (1607) (String_To_UniCode a) => "\\U+0647" (setq b "\U+554A") (ascii b) => 21834 (vl-string->list b) => (21834) (String_To_UniCode b) => "\\U+554A" 1 Quote Link to comment Share on other sites More sharing options...
granat Posted July 23, 2018 Share Posted July 23, 2018 I HAVE A FILE NAME IN UNICODE :(SETQ QFILE "D:\\\U+05D3\U+05D5\U+05E8\U+05D5\U+05DF\\DRAWING3.DWG") I CAN'T OPEN A NEW FILE (setq f (open qfile "w") 1 Quote Link to comment Share on other sites More sharing options...
granat Posted July 23, 2018 Share Posted July 23, 2018 ttps://www.youtube.com/watch?v=XkczYaBlbNY Problem displaying Arabic letters on windows - YouTube 1 Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted July 25, 2018 Share Posted July 25, 2018 I HAVE A FILE NAME IN UNICODE :(SETQ QFILE "D:\\\U+05D3\U+05D5\U+05E8\U+05D5\U+05DF\\DRAWING3.DWG")I CAN'T OPEN A NEW FILE (setq f (open qfile "w") hi, you only can write to asciii file, e.g .dxf, txt, csv etc.., but not a drawing file do you mean open a new drawing? just curious ac2007 ([color="blue"]ascii[/color] "\U+6C49") [color="green"];returns only 92 the first char[/color] 1 Quote Link to comment Share on other sites More sharing options...
granat Posted July 25, 2018 Share Posted July 25, 2018 hi, you only can write to asciii file, e.g .dxf, txt, csv etc.., but not a drawing file do you mean open a new drawing? just curious ac2007 ([color="blue"]ascii[/color] "\U+6C49") [color="green"];returns only 92 the first char[/color] ================================================= vlisp return the name of the folder in Unicode ?!? (setq a (strcat (getvar "dwgprefix")(setvar "dwgname"))) = D:\\\U+05D3\U+05D5\U+05E8\U+05D5\U+05DF\\DRAWING3 .DWG" because the folder name is in Hebrew : "D:\\דורון\\DRAWING3.DWG" I found the solution: Problem displaying Arabic letters on windows - YouTube ttps://www.youtube.com/watch?v=XkczYaBlbNY 1 Quote Link to comment Share on other sites More sharing options...
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.