mIRC Homepage

splitting a string into 4 chunks

Posted By: pouncer

splitting a string into 4 chunks - 09/10/09 10:19 AM

if i had something like $md5(blah)

6f1ed002ab5595859014ebf0951522d9

how could i split it into 4 chunks of 8 bytes like

6f1ed002
ab559585
9014ebf0
951522d9
Posted By: Horstl

Re: splitting a string into 4 chunks - 09/10/09 10:46 AM

Code:
alias example_mid {
  var %string = 6f1ed002ab5595859014ebf0951522d9
  var %b = 1, %n = 1
  while ($mid(%string,%b,8) != $null) {

    ; $v1 is the current chunk, e.g.:
    set -l $+(%,chunk.,%n) $v1

    inc %b 8
    inc %n
  }

  ; - do stuff with %chunk.1 to %chunk.4 -
}


alias example_regex {
  var %string = 6f1ed002ab5595859014ebf0951522d9
  noop $regex(example,%string,/(.{8})/g)

  ; $regml(example,N) is now filled with your chunks

  var %n = 1
  while ($regml(example,%n) != $null) {
    echo -a chunk %n is: $v1
    inc %n
  }
}

Posted By: pouncer

Re: splitting a string into 4 chunks - 09/10/09 10:51 AM

Thanks alot Horstl, what is the -sl switch, i dont see them in my mirc help file
Posted By: Horstl

Re: splitting a string into 4 chunks - 09/10/09 10:56 AM

-l sets a local variable (like /var, but I named the vars dynamically with %n)
-s (removed in my edit) will show the value to the active window.
Posted By: pouncer

Re: splitting a string into 4 chunks - 09/10/09 10:56 AM

and also

Quote:

22210219642164014968PROD0090YUAUV{2B0000
2221
0219
6421
6401
4968
PROD
0090
YUAU
V{2B


Im trying the same with this string, except in chunks of 4, and it isnt echoing the last 0000 (all i did was change the 8 to a 4 in your code)
Posted By: Horstl

Re: splitting a string into 4 chunks - 09/10/09 11:07 AM

I added a "!= $null" to my original post for this case smile

If you dislike the set -l thingie, you can use as well
Code:
var %chunk. $+ %n $v1
It's only a habit of mine to set/call "complex" variables with $+()
Posted By: s00p

Re: splitting a string into 4 chunks - 11/10/09 03:20 PM

Don't spoon-feed him anymore. I gave him an answer that leads directly to this question in a previous post, and it appears he isn't actually learning anything. Look at any of his posts, they're all questions and they all lead on to the next question.
Posted By: s00p

Re: splitting a string into 4 chunks - 11/10/09 03:36 PM

Please see my post for the reason this thread shouldn't exist: http://forums.mirc.com/ubbthreads.php?ubb=showflat&Number=215859&page=0#Post215859
Posted By: Lpfix5

Re: splitting a string into 4 chunks - 11/10/09 03:55 PM

You can always do a $len check on your string and divide that by the amount of chars per chunk you want and then base a while loop on it.

Code:
var %a = 6f1ed002ab5595859014ebf0951522d9, %b = $len(%a) \ 8, %c = My original result of %a as given me %b possible factors.
echo %c
Posted By: s00p

Re: splitting a string into 4 chunks - 13/11/09 09:34 PM

Naw, where the string is less than 32 bytes, they'll want 2nd 3rd and 4th chunk to be 8 bytes and the 1st chunk to be padded out to 8. Thank a moderator for the ressurection of many old posts.
© 2022 mIRC Discussion Forums