Author Topic: read string..  (Read 4557 times)

0 Members and 1 Guest are viewing this topic.

Andrea

  • Water Moccasin
  • Posts: 2372
read string..
« on: January 24, 2008, 10:11:35 PM »
Hi all,

i'm trying to found a simple way to read the S1 value ?

Code: [Select]
(setq S1 "User2\02\128\12\043\001\07")

!S1 = "User2\002\n8\n#\001\007"

(vl-string-search "128" S1) = nil

any suggestions ?
Keep smile...

FengK

  • Guest
Re: read string..
« Reply #1 on: January 24, 2008, 11:51:08 PM »
You mean (setq S1 "User2\\02\\128\\12\\043\\001\\07")?

daron

  • Guest
Re: read string..
« Reply #2 on: January 25, 2008, 12:03:09 AM »
Looks like you're trying to read an encrypted doc file.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: read string..
« Reply #3 on: January 25, 2008, 03:25:59 AM »
What output do you expect ?


(eval S1)

--> "User2\002\n8\n#\001\007"

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: read string..
« Reply #4 on: January 25, 2008, 06:47:34 AM »
Sorry to be daft but what is your objective?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: read string..
« Reply #5 on: January 25, 2008, 11:53:35 AM »
Sign hanging in doctor's office --

Quote
To avoid delay please have all your symptoms ready.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Andrea

  • Water Moccasin
  • Posts: 2372
Re: read string..
« Reply #6 on: January 25, 2008, 12:01:33 PM »
an external program create an .stg file who have specific data user information.

The objective is to read the information from this file and make the prog.
Code: [Select]
User2\02\128\12\043\001\07

User2 = User type
02 = Dιpartment
128 = encryption Module
12 = dont realy know..
001 = section program module
07 = link type

I can't tell really what the entire program do..(created by client)
but need to patch some bug.

Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: read string..
« Reply #7 on: January 25, 2008, 12:11:17 PM »
Are you saying you want to parse the string "User2\02\128\12\043\001\07" into separate tokens, say in a list ( "User2" "02" "128" "12" "043" "001" "07" )?

Also, does the string actually have embedded backslashes, i.e. "User2\\02\\128\\12\\043\\001\\07" as would be represented in lisp or is the string to be taken as literally expressed in your preceding post?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Andrea

  • Water Moccasin
  • Posts: 2372
Re: read string..
« Reply #8 on: January 25, 2008, 12:17:49 PM »
If I can parse the string it would be nice.

the string is as literally expression.


Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: read string..
« Reply #9 on: January 25, 2008, 12:28:38 PM »
the string is as literally expression.

Are you sure?

Code: [Select]
(defun _Parse ( text delim )

    ;;  note, delim is expeted to be a single character like ","

    (   (lambda ( lst delim / result token )
            (foreach code (reverse lst)
                (if (eq delim code)
                    (setq result (cons token result) token nil)
                    (setq token (cons code token))
                )
            )
            (mapcar 'vl-list->string
                (cons token result)
            )
        )
        (vl-string->list text)
        (ascii delim)
    )
)

(_Parse "User2\\02\\128\\12\\043\\001\\07" "\\")

Returns the list --

("User2" "02" "128" "12" "043" "001" "07")

But the literal lisp string "User2\02\128\12\043\001\07" would be more difficult to parse into tokens unless there is a fixed and predictable token length to use as the means to delimit the beginning and end of each token definition.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Andrea

  • Water Moccasin
  • Posts: 2372
Re: read string..
« Reply #10 on: January 25, 2008, 12:58:57 PM »
Thank you MP for your parse code....

but I already have mine..

Code: [Select]
(defun myparse (str sym / #sym)
(setq str (strcat str sym))
(setq list1 ())
(while (setq #sym (vl-string-search sym str))
  (setq list1 (append list1 (list (substr str 1 #sym))))
  (setq str (substr str (+ #sym 2)))
)
list1
)

use:
(myparse "User2\\02\\128\\12\\043\\001\\07" "\\")

I think the problem still the "\" symbol.

Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: read string..
« Reply #11 on: January 25, 2008, 01:11:47 PM »
If that string is a lisp literal perhaps what you're failing to recognize is that the blue parts are evaluated as ASCII characters and the red parts are evaluated as octal character codes: "User2\02\128\12\043\001\07".
« Last Edit: January 25, 2008, 01:18:08 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Andrea

  • Water Moccasin
  • Posts: 2372
Re: read string..
« Reply #12 on: January 25, 2008, 01:44:07 PM »
Ok there is a sample of the stg file..

The file is a little bigger
(i've removed personal client information)

I'm trying to parse the first line.



Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: read string..
« Reply #13 on: January 25, 2008, 02:04:52 PM »
The string literal is "uSER1\003\001\031\036\031" per this. If the token lengths are known simply use substr.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: read string..
« Reply #14 on: January 25, 2008, 02:24:06 PM »
Quick and Dirty --

Code: [Select]
(defun _ParseByWidth ( text widths )

    (   (lambda ( lst widths / width token result )
   
            (while (and lst widths)

                (setq
                    width  (car widths)
                    widths (cdr widths)
                )
               
                (while (and lst (< (length token) width))
                    (setq
                        token (cons (car lst) token)
                        lst   (cdr lst)
                    )                       
                )
           
                (setq
                    result (cons token result)
                    token  nil
                )
            )
           
            (mapcar 'vl-list->string
                (mapcar 'reverse
                    (reverse
                        (if token
                            (cons token result)
                            result
                        )                                                 
                    )
                )                 
            )
   
        )
       
        (vl-string->list text)
       
        widths
       
    )   

)

(_ParseByWidth "uSER1\003\001\031\036\031" '(5 1 1 1 1 1))

returns

("uSER1" "\003" "\001" "\031" "\036" "\031")
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst