XGamerGuide Posted June 23, 2021 Share Posted June 23, 2021 I want to get an array from a string with all parts that are not a string. For example: das hier "ist 'ein "test 'string"p""'p"m'm'm" This should be in the array: das hier test p Link to comment Share on other sites More sharing options...
dmob Posted June 24, 2021 Share Posted June 24, 2021 (edited) Have you tried _StringBetween? EDIT: Yooh!! Is this your real data or a made up "string' "? Edited June 24, 2021 by dmob Link to comment Share on other sites More sharing options...
XGamerGuide Posted June 24, 2021 Author Share Posted June 24, 2021 Quote Have you tried _StringBetween? Thanks but _StringBetween is not what I'm looking for. With this function I can only use " " or ' '. This doesn't work with stings like "hello'test'string". This is ONE string Link to comment Share on other sites More sharing options...
Musashi Posted June 24, 2021 Share Posted June 24, 2021 4 hours ago, dmob said: EDIT: Yooh!! Is this your real data or a made up "string' "? I have already asked this question myself . @XGamerGuide : Can you post a script snippet where you have assigned this "string" to a variable, meaning something like : [...] Local $sString = [your string] [...] The string contains quite a mess of single and double quotes. Where does it actually come from ? "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
XGamerGuide Posted June 24, 2021 Author Share Posted June 24, 2021 (edited) Quote an you post a script snippet where you have assigned this "string" to a variable FileRead() Edited June 24, 2021 by XGamerGuide Link to comment Share on other sites More sharing options...
Musashi Posted June 24, 2021 Share Posted June 24, 2021 23 minutes ago, XGamerGuide said: FileRead() Ok ! I assume, that there are multiple lines. Do they all follow this structure ? "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
XGamerGuide Posted June 24, 2021 Author Share Posted June 24, 2021 Quote I assume, that there are multiple lines. Do they all follow this structure ? I am currently programming a program that compresses an Autoit Script. To do this, each line is split into an array and read out in a loop. For example, to remove a comment with ; my program needs to know whether this character is in a string or not. Link to comment Share on other sites More sharing options...
Dan_555 Posted June 24, 2021 Share Posted June 24, 2021 (edited) This works on your test case: expandcollapse popup#include <Array.au3> Dim $a_array[0]=[] $file = FileRead(@ScriptDir & "\" & "text.txt") $c = Chr(34) ; " $d = Chr(39) ; ' $getchar = "" $tmptxt = "" ;StartC, StartD $sc = 0 $sd = 0 For $x = 1 To StringLen($file) $getchar = StringMid($file,$x,1) If $getchar = $c And $sd = 0 And $sc = 0 Then If StringLen($tmptxt) > 0 Then _ArrayAdd($a_array, $tmptxt) $tmptxt = "" EndIf $sc = 1 ElseIf $getchar = $d And $sd = 0 And $sc = 0 Then If StringLen($tmptxt) > 0 Then _ArrayAdd($a_array, $tmptxt) $tmptxt = "" EndIf $sd = 1 ElseIf $getchar = $c And $sd = 0 And $sc = 1 Then $sc = 0 $getchar="" ElseIf $getchar = $d And $sd = 1 And $sc = 0 Then $sd = 0 $getchar="" EndIf If $sc = 0 And $sd = 0 Then $tmptxt = $tmptxt & $getchar Next if $sc=0 and $sd=0 and StringLen($tmptxt)>0 then _ArrayAdd($a_array, $tmptxt) For $x=0 to UBound($a_array)-1 CW($a_array[$x]) Next Func CW($txt, $crlf = 1) Local $nl = "" If $crlf = 1 Then $nl = @CRLF ConsoleWrite($txt & $nl) EndFunc ;==>CW I haven't tested all cases. Edit: removed 2 meaningless assignment of the $tmptxt variable. Edited June 24, 2021 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Musashi Posted June 24, 2021 Share Posted June 24, 2021 12 minutes ago, XGamerGuide said: I am currently programming a program that compresses an Autoit Script. To do this, each line is split into an array and read out in a loop. For example, to remove a comment with ; my program needs to know whether this character is in a string or not. Ok, that at least throws some light into the darkness . Maybe a stupid question, but have you ever taken a look at the functionalities of Tidy ? 9 minutes ago, Dan_555 said: This works on your test case: I tried to do something similar using "StringRegExpReplace", but all the quotes are not so easy to handle. You probably finished your solution before @XGamerGuide described the actual goal of his project . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
XGamerGuide Posted June 24, 2021 Author Share Posted June 24, 2021 Quote This works on your test case: Thanks that helped me further. I had to rewrite the function a bit, but it works Link to comment Share on other sites More sharing options...
Dan_555 Posted June 24, 2021 Share Posted June 24, 2021 Yeah, i was writing for the test example from the 1st post: Quote das hier "ist 'ein "test 'string"p""'p"m'm'm" Some of my script sourcecode Link to comment Share on other sites More sharing options...
XGamerGuide Posted June 24, 2021 Author Share Posted June 24, 2021 Quote Maybe a stupid question, but have you ever taken a look at the functionalities of Tidy ? If the code of Dan_555 shows errors I will take a closer look Thanks Link to comment Share on other sites More sharing options...
Musashi Posted June 24, 2021 Share Posted June 24, 2021 Just out of curiosity : What exactly do you intend when you write : 42 minutes ago, XGamerGuide said: I am currently programming a program that compresses an Autoit Script. Will the script still be human-readable in the end, or what do you want to achieve by using 'your compression'? "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
XGamerGuide Posted June 24, 2021 Author Share Posted June 24, 2021 Quote Will the script still be human-readable in the end, or what do you want to achieve by using 'your compression'? After compression, the script should only be read by the Autoit interpreter and no longer by programmers. This makes the file smaller Link to comment Share on other sites More sharing options...
mikell Posted June 24, 2021 Share Posted June 24, 2021 (edited) And why not... guess what ? #Include <Array.au3> $s = StringStripWS(FileRead("test.txt"), 2) ; use a replacement character to replace the 'string' parts $s = StringRegExpReplace($s, '([''"]).*?\1', ChrW(0xFFFD)) ; then split $res = StringSplit(StringTrimRight($s, 1), ChrW(0xFFFD), 3) _ArrayDisplay($res) Edit Simpler but assumes that the non-string parts contain word chars and/or spaces only, one or more (to be adapted if needed) #Include <Array.au3> $s = StringStripWS(FileRead("test.txt"), 2) $res = StringRegExp($s, '([''"]).*?\1(*SKIP)(*F)|[\w\s]+', 3) _ArrayDisplay($res) Edited June 24, 2021 by mikell XGamerGuide and Musashi 2 Link to comment Share on other sites More sharing options...
Musashi Posted June 24, 2021 Share Posted June 24, 2021 16 minutes ago, XGamerGuide said: After compression, the script should only be read by the Autoit interpreter and no longer by programmers. This makes the file smaller Then it is more of an Obfuscator, not a Compressor . I don't want to criticize your project, but just reducing the file size is, in my opinion, not a sufficient reason for all the effort. For example, if I look at one of my larger scripts (4000+ lines and 10+ includes) , it's just 150 KB. In times of Terabyte HDDs this is next to nothing. If, on the other hand, you want to protect your scripts against access by people with little knowledge, then compiling them as .a3x would be a possible solution. However, it is your spare time and you can do whatever you feel comfortable with . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Musashi Posted June 24, 2021 Share Posted June 24, 2021 17 minutes ago, mikell said: And why not... guess what ? What took you so long ? Nice job. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
jchd Posted June 24, 2021 Share Posted June 24, 2021 2 hours ago, XGamerGuide said: I am currently programming a program that compresses an Autoit Script. To do this, each line is split into an array and read out in a loop. For example, to remove a comment with ; my program needs to know whether this character is in a string or not. Isn't that (and more) that #AutoIt3Wrapper_Run_Au3Stripper=y would do? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
XGamerGuide Posted June 24, 2021 Author Share Posted June 24, 2021 Quote And why not... guess what ? Thanks, works great Quote For example, if I look at one of my larger scripts (4000+ lines and 10+ includes) , it's just 150 KB. In times of Terabyte HDDs this is next to nothing. In my program it is also base54 encoded. That makes the file 30% larger after times. I don't want it to take so long to decode. Link to comment Share on other sites More sharing options...
XGamerGuide Posted June 24, 2021 Author Share Posted June 24, 2021 Quote Maybe a stupid question, but have you ever taken a look at the functionalities of Tidy ? I have more plans for my program than what Tidy can do Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now