Aide avec la fonction personnaliséehash = Function( {StringList},
{StringListItem,HashString},
For( StringListItem = 1, StringListItem <= Length( StringList ), StringListItem++,
StringList[StringListItem] = Char( Eval( Stringlist[StringListItem] ) )
);
HashString = Hex( Blob MD5( Char To Blob( Concat Items( StringList ) ) ) );
);Il s'agit d'une fonction de hachage que j'utilise pour créer des identifiants uniques.La fonction prend actuellement une liste comme argument.Je voudrais qu'il prenne un ou plusieurs arguments séparés par des virgules.J'espère l'ajouter à des fonctions personnalisées et le mettre à la disposition d'autres utilisateurs.Je pensais que ce serait plus facile pour les utilisateurs s'il acceptait plusieurs arguments séparés par des virgules comme la fonction Sum().
Des pensées?
Merci beaucoup,
John
Re : Aide sur la fonction personnaliséeUn grand merci pour votre solution !Re : Aide sur la fonction personnalisée@johnmoore ,
Ceci est une autre variante de @vince_faller et @txnelson les solutions.
Names default to here(1);
hash = Function( {val1, val2=., val3=., val4=., val5=., val6=., val7=., val8=., val9=., val10=.},
{i, StringListItem,HashString},
if(IsList(val1), StringList = EvalList(val1),
StringList={};
For(i=1, i<=10,i++,
Eval( Parse(EvalInsert("If( !IsMissing(val^i^) & IsString(val^i^), InsertInto(StringList, val^i^))" ) ) )
);
);
//Show(StringList);
For( StringListItem = 1, StringListItem <= Length( StringList ), StringListItem++,
StringList[StringListItem] = Char( Eval( Stringlist[StringListItem] ) )
);
HashString = Hex( Blob MD5( Char To Blob( Concat Items( StringList ) ) ) );
);
x = "2";
y = "a";
z = "Expr(b)";
b = "another string";
hash(x,y,z);
l = {x, y, z};
show(hash(l), hash(x,y,z), hash( list(x,y,z) ) ); //produces the same result
Il faudrait une documentation/formation pour vos utilisateurs, que jusqu'à 10 arguments de chaîne peuvent être entrés ou utiliser une liste si plus de 10.
Re : Aide sur la fonction personnaliséeCe n'est peut-être pas exactement ce que vous recherchez, mais vous pouvez simplement évaluer s'il ne s'agit vraiment que d'une liste de chaînes.
Les arguments inconnus infinis sont plus faciles avec une liste.
Names default to here(1);
hash = Function( {StringList},
{StringListItem,HashString},
For( StringListItem = 1, StringListItem <= Length( StringList ), StringListItem++,
StringList[StringListItem] = Char( Eval( Stringlist[StringListItem] ) )
);
HashString = Hex( Blob MD5( Char To Blob( Concat Items( StringList ) ) ) );
);
different_hash = function({StringList},
StringList = Evallist(StringList);
Hex( Blob MD5( Char To Blob( Concat Items( StringList ) ) ) );
);
x = "2";
y = "a";
z = "Expr(b)";
b = "another string";
l = {x, y, z};
show(hash(l) == different_hash(l));Re : Aide sur la fonction personnaliséeVoici une méthode utilisant votre code qui permettrait l'entrée d'un grand maximum prédéfini, mais une liste variable de paramètres d'entrée pour votre fonction de hachage
hash = Function( {a, b = "", c = "", d = ""}, // e="",f=""...…...z="")
//{StringListItem,HashString},
StringList = {};
string# = 1;
varList = {"a", "b", "c", "d"}; // .........."z"
While( Eval( Parse( varlist[string#] ) ) != "",
Insert Into( stringList, Eval( Parse( varlist[string#] ) ) );
string# = string# + 1;
);
For( StringListItem = 1, StringListItem <= Length( StringList ), StringListItem++,
StringList[StringListItem] = Char( Eval( Stringlist[StringListItem] ) )
);
HashString = Hex( Blob MD5( Char To Blob( Concat Items( StringList ) ) ) );
);