Recréation de $gettok en $g3ttok

Contenu du snippet

Tout est dans le titre (bis)

Source / Exemple :


;recréation de $gettok. Syntaxe: $g3ttok(chinois,est,maintenant,ugly,2,44) . Retourne "est" ;5]
;$gettok(chinois-est-maintenant-ugly,2,45)       ; return "est"
;$g3ttok(chinois-est-maintenant-ugly,2,45)       ; return "est"
;$gettok(chinois,est,maintenant,ugly,2,44)       ; return "* Too many parameters: $gettok"
;$g3ttok(chinois,est,maintenant,ugly,2,44)       ; return "est"
;$gettok(chinois est maintenant ugly,0,32)       ; return "4"
;$g3ttok(chinois est maintenant ugly,0,32)       ; return "il y a 4 tokens"
;$gettok(chinois-est-maintenant-ugly,-4,45)      ; return "chinois"
;$g3ttok(chinois-est-maintenant-ugly,-4,45)      ; return "chinois"
;$gettok(chinois-est-maintenant-ugly,2-,45)      ; return "est-maintenant-ugly"
;$g3ttok(chinois-est-maintenant-ugly,2-,45)      ; return "est-maintenant-ugly"
;$gettok(chinois-est-maintenant-ugly,2-3,45)    ; return "est-maintenant"
;$g3ttok(chinois-est-maintenant-ugly,2-3,45)    ; return "est-maintenant"

g3ttok {
  ;if $chr(44) !isin $1- { return * Parametres invalides: $+($,g3ttok) }
  if (!$3) { return * Parametres invalides: $+($,g3ttok) }
  if $+(4,4) isin $right($1-,2) {
    var %a = $replace($1-,$chr(32),$chr(43)), %b = $count(%a,+), %c = $+($pos(%a,+,$calc(%b -1)),-), %d = $replace($mid($1-,%c,99),$chr(32),$chr(44)), %e = $remove($1-,$mid($1-,%c,999)), %f = $+(%e,%d), %$$2 = $remove($mid(%d,1,$pos(%d,$chr(44),$count(%d,$chr(44)))),$chr(44)), %$$3 = $remove($mid(%d,$pos(%d,$chr(44),$count(%d,$chr(44))),99),$chr(44)), %v. = on
  var %g = $numtok(%e,32), %h = 1, %i = "", %j = 1 | while %h <= %g { %i = %j | %j = $iif(%h = %g,999,$pos(%e,$chr(32),%h)) | var %$ [ $+ [ %h ] ] $mid(%e,[ %i ],$calc(%j - %i)) | inc %h } }
  else { var %a = $numtok($1,$3), %b = 1, %c = "", %d = 1 | while %b <= %a { %c = %d | %d = $iif(%b = %a,999,$pos($1,$chr($3),%b)) | var %$ [ $+ [ %b ] ] $mid($1,[ %c ],$calc(%d - %c)) | inc %b } }
  if $chr($+(4,5)) isin $left([ %$$2 ],1) { var %k = $calc($numtok(%e,32) - $abs(%$$2) +1) | return $remove(%$ [ $+ [ %k ] ],32)) }
  elseif $chr($+(4,5)) isin $right([ %$$2 ],1) { var %k = "",%$$4 = $remove(%$$2,$chr(45)), %$$5 = %$$4 | while %$$4 <= $calc(%b -1) { $iif(%$$4 = %$$5,%k = $mid(%$ [ $+ [ %$$4 ] ],2,999), %k = $+(%k,$chr(44),$mid(%$ [ $+ [ %$$4 ] ],2,999))) | $iif(%$$4 = 1,%k = %$ [ $+ [ %$$4 ] ]) | inc %$$4 } | return %k }
  elseif $chr($+(4,5)) isin $mid([ %$$2 ],$calc($len([ %$$2 ]) /2+1),1) { var %k = "",%$$4 = $left([ %$$2 ],$calc($len([ %$$2 ]) /2)),%$$5 = $remove($right([ %$$2 ],$calc($len([ %$$2 ]) /2)),$chr($+(4,5))),%$$6 = %$$4 | while %$$4 <= %$$5 { $iif(%$$4 = %$$6,%k = $mid(%$ [ $+ [ %$$4 ] ],2,999), %k = $+(%k,$chr(44),$mid(%$ [ $+ [ %$$4 ] ],2,999))) | $iif(%$$4 = 1,%k = %$ [ $+ [ %$$4 ] ]) | inc %$$4 } | return %k }
  elseif %$$2 = 0 { return il y a $numtok(%e,32) tokens }
  elseif %v. = on { return $iif(!%$ [ $+ [ %$$2 ] ],* Parametres invalides: $+($,g3ttok),$remove(%$ [ $+ [ %$$2 ] ],32)) }
  elseif $chr($+(4,5)) isin $left($2,1) { var %k = $calc( [ %a ] - $abs($2) +1) | return $remove(+%$ [ $+ [ %k ] ],$chr($3)) }
  elseif $chr($+(4,5)) isin $right($2,1) { var %k = "",%$$4 = $remove($2,$chr(45)), %$$5 = %$$4 | while %$$4 <= $calc(%b -1) { $iif(%$$4 = %$$5,%k = $mid(%$ [ $+ [ %$$4 ] ],2,999), %k = $+(%k,$chr($3),$mid(%$ [ $+ [ %$$4 ] ],2,999))) | $iif(%$$4 = 1,%k = %$ [ $+ [ %$$4 ] ]) | inc %$$4 } | return %k }
  elseif $chr($+(4,5)) isin $mid($2,$calc($len($2) /2+1),1) { var %k = "",%$$4 = $left($2,$calc($len($2) /2)),%$$5 = $remove($right($2,$calc($len($2) /2)),$chr($+(4,5))),%$$6 = %$$4 | while %$$4 <= %$$5 { $iif(%$$4 = %$$6,%k = $mid(%$ [ $+ [ %$$4 ] ],2,999), %k = $+(%k,$chr($3),$mid(%$ [ $+ [ %$$4 ] ],2,999))) | $iif(%$$4 = 1,%k = %$ [ $+ [ %$$4 ] ]) | inc %$$4 } | return %k }
  elseif $2 = 0 { return il y a %a tokens }
else return $iif(!%$ [ $+ [ $2 ] ],* Parametres invalides: $+($,g3ttok) ,$remove(%$ [ $+ [ $2 ] ],$chr($3))) }

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.

Du même auteur (c0wz)