Sign in to follow this  
Followers 0
SadBunny

(_)StringSplit and trying to use strings as delimiters

7 posts in this topic

Hi! I would like to pose a question about StringSplit and/or _StringSplit.

What I would like to to is split a BIG BIG string (an mp3 file, binary-read to an enourmous hex string (a 1.2 MB 128 kbps file is my test)) into it's frames.

For this, the hex string would need to be split on two delimiters. Problem is, these delimiters are "FFE?" and "FFF?" (11111111 111?????). I don't suppose there is a way to put two STRINGS as two single delimiters into one StringSplit concoction? (Or to use a RegEx as a delimiter which would be even more elegant?)

I can easily do it manually but then I need to work myself through the string, but StringSplit is like 1000x faster than tens of thousands of StringInStr and StringLeft commands on a 2 MB string.


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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi! I would like to pose a question about StringSplit and/or _StringSplit.

What I would like to to is split a BIG BIG string (an mp3 file, binary-read to an enourmous hex string (a 1.2 MB 128 kbps file is my test)) into it's frames.

For this, the hex string would need to be split on two delimiters. Problem is, these delimiters are "FFE?" and "FFF?" (11111111 111?????). I don't suppose there is a way to put two STRINGS as two single delimiters into one StringSplit concoction? (Or to use a RegEx as a delimiter which would be even more elegant?)

I can easily do it manually but then I need to work myself through the string, but StringSplit is like 1000x faster than tens of thousands of StringInStr and StringLeft commands on a 2 MB string.

Just use RegEx as you were thinking. "(?i)(.*?)(?:\z|FFE\?|FFF\?)" along with 3 as the third parameter. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

You could just do 2 StringSplit()

$a=StringSplit($string,"FFE?")

if @error=1 then

$a=StringSplit($string,"FFF?")

Share this post


Link to post
Share on other sites

SMOKE! Good to see you are still active! :o I haven't been on here for months, and I get back and BLAMMO there is the answer! :D

But... It doesn't work, since I probably haven't been clear on what I need. I'm sure it can be done with RegEx, and I tried something like this before, but am not proficient enough at RegEx to cut it. The ? in my example stood for a random character, I don't actually have "?" in a hex string... :D And I need the FFF and FFE included in the regex result, not excluded, only split on every occurance. I'm sure this makes the regex string even simpler but I just don't see it.

What I have tried:

In English, I would need elements with <everything until next (FFE or FFF) or endofline>. This would make all my elements (except for the first one which is always "0x") start with FFE or FFF and go to the place just before the next FFE or FFF.

The best I can come up with is "(.*?)(FFE|FFF|\z)" and that ALMOST works, but gives me things like the string split both before and after the FFE/FFF. So I am trying to make the string split ONLY before it and NOT after it. I'm sure I'm missing something in RegEx.

And what exactly is the question mark at the end of a group, as in "(.*?)" ? I don't see that documented in the StringRegExp helpfile.

Thanks!

You could just do 2 StringSplit()

$a=StringSplit($string,"FFE?")

if @error=1 then

$a=StringSplit($string,"FFF?")

Thanks, but that won't work... That renders the first stringsplit useless and only gives me the full string split in "FFF?"...


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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I would attack it like this:

#include <Array.au3>

$File = "FFF?c56d5c65d5dc5FFE?5565hd5hd65FFF?12c1b2cb";etc, etc

$File = StringReplace($File,"FFF","|FFF")
$File = StringReplace($File,"FFE","|FFE")

$aFrames = StringSplit($File,"|")

_ArrayDisplay($aFrames)

.... could take a while though?

[EDIT] Sorry, didn't read clarification properly! Code changed slightly

[EDIT2]

or perhaps this will be quicker?:

#include <Array.au3>

$File = "FFF?c56d5c65d5dc5FFE?5565hd5hd65FFF?12c1b2cb";etc, etc
$File = StringRegExpReplace($File,"(FFF|FFE)","¬\0")
$aFrames = StringSplit($File,"¬")
_ArrayDisplay($aFrames)

Sorry if i'm not helping here - I'm a RegEx dufus too :D

Edited by andybiochem

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites

"(.*?(?:FFE|FFF|\z))"

.*? the ? there is a lazy search.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I would attack it like this:

#include <Array.au3>

$File = "FFF?c56d5c65d5dc5FFE?5565hd5hd65FFF?12c1b2cb";etc, etc

$File = StringReplace($File,"FFF","|FFF")
$File = StringReplace($File,"FFE","|FFE")

$aFrames = StringSplit($File,"|")

_ArrayDisplay($aFrames)
Wow, that was exactly the workaround I came up with after I gave up the regex. Worked like a mofo! And almost as fast as the regexp even though tens of thousands elements needed to be read.

Thanks for helping!

Smoke, thanks even more, I'll look into your second regex suggestion asap.


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  
Followers 0