Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I have a question regarding hashing. I need to hash a field in the loadscript, and make the output 2 characters the set 'a..z A..Z".
I'm aware that I can do: left(hash128(field),2), however, this gives me a lot of "unwanted characters" liek '(/&%¤#' etc,,,
It seems very hard to do in one statement...
In C, this would be a quite trivial execise, however, I'm not sure how to solve this in a nice and efficient way in qlickview.
Any suggestions? Do I need to make custom functions? (is that possible?)
best regards
JF
Here are two script solutions. I haven't thought of how to turn an arbitrary string of characters into an integer in the front end. You can make "custom functions" with parameterized dollar sign expansion, and I can go into that in more detail if you'd like.
[Characters]:
LOAD chr(ord('A')+recno()-1) as Char AUTOGENERATE 26;
LOAD chr(ord('a')+recno()-1) as Char AUTOGENERATE 26;
[Character Map]:
MAPPING LOAD recno()-1 as Num, Char RESIDENT [Characters];
DROP TABLE [Characters];
[Data]:
LOAD
recno() as ID
// You'd hash something other than recno() in a real application. It doesn't have to be a number.
,applymap('Character Map',mod(floor(autonumberhash128(recno())/52),52))
&applymap('Character Map',mod( autonumberhash128(recno()) ,52)) as Hashed
,mid('ABCDEFGHIJKLMNOPQRXTUVWXYZabcdefghijklmnopqrstuvwxyz',mod(floor(autonumberhash128(recno())/52),52)+1,1)
&mid('ABCDEFGHIJKLMNOPQRXTUVWXYZabcdefghijklmnopqrstuvwxyz',mod( autonumberhash128(recno()) ,52)+1,1) as Hashed2
AUTOGENERATE 3000
;
Hi JF,
After applying hash128 function use keepchar function to purge all unnecessary characters. If you need to do more explore string functions in qv help like purgechar,replace etc..
Its possible to make custom functions but could be used only at script level. Go to module editor (CTRL+M), create a VB or Jscript function which can be called in the script just as a native qv function. But this is not recommended unless there is no way out.
Hope this helps.
Kiran.
I thought about that approach, however, that doesn't guarantee returning 2 characters, as a hash 128() could return only "strange" as well. While it is not very likely that the function doesn't return 2 normal characters, I would have to loop the function somehow until it does.
What is the primary reason for not creating custom functions? Performance?
Here are two script solutions. I haven't thought of how to turn an arbitrary string of characters into an integer in the front end. You can make "custom functions" with parameterized dollar sign expansion, and I can go into that in more detail if you'd like.
[Characters]:
LOAD chr(ord('A')+recno()-1) as Char AUTOGENERATE 26;
LOAD chr(ord('a')+recno()-1) as Char AUTOGENERATE 26;
[Character Map]:
MAPPING LOAD recno()-1 as Num, Char RESIDENT [Characters];
DROP TABLE [Characters];
[Data]:
LOAD
recno() as ID
// You'd hash something other than recno() in a real application. It doesn't have to be a number.
,applymap('Character Map',mod(floor(autonumberhash128(recno())/52),52))
&applymap('Character Map',mod( autonumberhash128(recno()) ,52)) as Hashed
,mid('ABCDEFGHIJKLMNOPQRXTUVWXYZabcdefghijklmnopqrstuvwxyz',mod(floor(autonumberhash128(recno())/52),52)+1,1)
&mid('ABCDEFGHIJKLMNOPQRXTUVWXYZabcdefghijklmnopqrstuvwxyz',mod( autonumberhash128(recno()) ,52)+1,1) as Hashed2
AUTOGENERATE 3000
;
OMG OMG :=) That is one amazing answer! Loved the simplicity of Hashed2 example!