mIRC Home    About    Download    Register    News    Help

Print Thread
splitting a string into 4 chunks #215820 09/10/09 10:19 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
if i had something like $md5(blah)

6f1ed002ab5595859014ebf0951522d9

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

6f1ed002
ab559585
9014ebf0
951522d9

Re: splitting a string into 4 chunks [Re: pouncer] #215821 09/10/09 10:46 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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
  }
}


Last edited by Horstl; 09/10/09 10:50 AM.
Re: splitting a string into 4 chunks [Re: Horstl] #215822 09/10/09 10:51 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Thanks alot Horstl, what is the -sl switch, i dont see them in my mirc help file

Re: splitting a string into 4 chunks [Re: pouncer] #215823 09/10/09 10:56 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
-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.

Re: splitting a string into 4 chunks [Re: pouncer] #215824 09/10/09 10:56 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
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)

Last edited by pouncer; 09/10/09 10:57 AM.
Re: splitting a string into 4 chunks [Re: pouncer] #215825 09/10/09 11:07 AM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
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 $+()

Re: splitting a string into 4 chunks [Re: Horstl] #215858 11/10/09 03:20 PM
Joined: Jul 2008
Posts: 236
S
s00p Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
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.

Re: splitting a string into 4 chunks [Re: pouncer] #215860 11/10/09 03:36 PM
Joined: Jul 2008
Posts: 236
S
s00p Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
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

Re: splitting a string into 4 chunks [Re: s00p] #215864 11/10/09 03:55 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
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


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: splitting a string into 4 chunks [Re: Lpfix5] #216409 13/11/09 09:34 PM
Joined: Jul 2008
Posts: 236
S
s00p Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
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.