Jump to content

vl-list->string, hex notation, and oh god why I can't write this string to a file


Kreaten_vhar

Recommended Posts

How's it going everybody?

 

Today I write because I have been banging my head against a wall trying to find out why I can't write the output of a vl-list->string to a text file.

 

I have a list that's equal to (0 1 2), I run that through vl-list->string and get the ASCII codes as a string in the form of "\000\001\002" as the output. So I then save that string to a variable, say, VariableWithString. All good so far.

When I attempt to write this string of ASCII codes to a file using (write-line VariableWithString File) what gets written to the file is just a blank new-line (other write-line statements get written fine.) Not so good now, but I figure I could fix it.

 

Well I can't really figure it out :wacko:

At first I figured there was some escape character shenanigans going on, so I tried to append extra \'s to the string. vl-string-translate wasn't able to pick up on the existing \'s however.

I have made some progress, such as noticing that a statement such as (vl-string-translate "0" "/0" VariableWithString) will actually replace the \000 with just a plain 0, but this solution makes later coding a bit more difficult/tedious cause the initial list can vary in size quite a bit. I'd very much like to be able to get the exact string, that whole "\000\001\002" written to the file so I can later just do a quick vl-string->list to get my list back, or at the least a version of the string that I could easily restore to the proper form to get my list back. 

 

And I figure it's worth mentioning I'm on BricsCAD 

 

Thanks ahead of time all for any help/insight you can offer! 
 

Link to comment
Share on other sites

That is a list of integers they need to be converted to strings to be written to a file.

 

(foreach x lst
  (if (numberp x)
    (writeline (rtos x 2 0))
    (writeline x)
  )
)
Edited by mhupp
number checking
  • Thanks 1
Link to comment
Share on other sites

Oh hey, yeah, that actually works quite well. I was definitely too deep into the vl-list->string rabbithole and wasn't thinking about just breaking down my list into strings using another method lol :ouch:

  • Like 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...