Jump to content
Sign in to follow this  

How to include a complex text file as a string inside the script?

Recommended Posts

Hey people!

Been using Autoit for some time and now I'm facing an issue.

First of all, I do not want to use fileinstall.

I'd like to know how could I format text in order to have it included as is as a string.

For example, adding a text similar to the one below poses the challenge for me of formating the strings in such a way to respect the EOL and TAB characters, to name a few:

Example list

- Line 1
- Line 2, this might have more text


Another sections... hope you catch my drift!

Anyway, I could manually do this (I'm including part of the text only):

$String = 'Example list below:' & @CRLF & @CRLF & '- Line 1'

How could I automate this conversion process to a format that could be decoded as the original by Autoit? Base 64? Binary?
 I'm a bit lost!

Thanks guys, hope you get what I meant!

Share this post

Link to post
Share on other sites

OK, I'm one of those annoying guys that replies to his own question five minutes later, hahaha!

Maybe useful for someone googling for that in the future!

Anyway, pretty easy. Just make an array of all the files to convert using _filelisttoarrayrec.

Then, use _StringToHex on each, output to a file. All I need to do is paste the hex code in the .au3 file and then use_HexToString to convert back and read the string.

When I get time to do it, I'll post the code!

Share this post

Link to post
Share on other sites

I don't think there's something like ending a line in to escape the newline and continue the string, or anything... But how about a search&replace instead of hex code?

(This assumes you use SciTE.)

1. Paste the text straight into SciTE

2. Select the pasted text

3. Escape any doublequotes by search&replace " by "" (doublequote by double doublequote) in your selection

4. Select your text again

5. Then search&replace in regex mode, find:     (.*)     replace by:     $x = $x & "1" & @CRLF

6. If necessary, remove the last @CRLF manually.

Maybe there are much better ways to go about this, but this has often worked for me in the past when writing quick scripts requiring some multiline string containing other script code, for instance. Though I much prefer reading from file, because it's probably less work and faster :)

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...