PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
GetId() |
This is an inbuilt function function provided by PPWIZARD.
This function is produces a unique string from your text and can ensure that the new string only contains "valid" characters and can be limited in length.
This can be useful when you wish to use a value as a key of some sort. For the value that you pass, this routine will determine a unique key (or ID) of the format you requested.
The routine has a memory and will always return the same ID for the same value.
Note that if you currently search array elements then you know that this is slow. Generating unique rexx variable names for a string allows you to save the information for "keyed" access, that is absolutely no searching required to locate the information!
The fastest and typically easiest way of generating a "key" is with the standard rexx "c2x()" built in routine. All characters generated by "c2x()" will be valid in a rexx variable name and as long as you prefix it with something alphabetic you will generate a valid rexx variable name. Its major deficiency is that it doubles the string length (not counting a constant prefix) and this can cause problems on some interpreters (not regina) which usually have variable name restrictions of 250 characters or so). Another major disadvantage is that if the key is visible (say if used to generate a filename) then it is absolutely cryptic (can also make debugging harder)!
My recommendation is that if you don't have length restrictions and the key is not visible (or you don't care what a filename looks like etc) then you would be crazy not to use "c2x()" as it is extremely fast, otherwise this "GetId()" routine should be used.
The function takes at least 3 parameters as follows:
The upper and lower case characters as well as zero to nine are always valid characters. You may specify additional valid characters in the optional 4th parameter to this function.
The upper and lower case characters as well as zero to nine are always valid characters. You may specify additional valid characters in the optional 4th parameter to this function.
The optional 5th parameter specifies the maximum number of characters in an ID with the default being 8.
This type can be used to generate file names for a 8.3 based file system.
The upper and lower case characters as well as zero to nine are always valid characters. You may specify additional valid characters in the optional 4th parameter to this function.
Example |
;--- Example #1 --- #evaluate '' ^call GetIdPrepare 'PPW'^ #evaluate '' ^call SetId 'PPW', '#define', "HashDef"^ ;;Set preferred ID #evaluate '' ^say GetId('PPW', 'MAXCHARS', 'define')^ #evaluate '' ^say GetId('PPW', 'MAXCHARS', '#define')^ #evaluate '' ^say GetId('PPW', 'MAXCHARS', 'define it')^ #evaluate '' ^say GetId('PPW', 'MAXCHARS', 'define')^ #evaluate '' ^say GetId('PPW', 'MAXCHARS', 'aaaaaaaaaaaaaaaa',, 10)^ ;;Max 10 chars #evaluate '' ^say GetId('PPW', 'MAXCHARS', 'aaaaaaaaaaaaaaab',, 10)^ #evaluate '' ^say GetId('PPW', 'MAXCHARS', 'aaaaaaaaaaaaaaac',, 10)^ #evaluate '' ^say GetId('PPW', 'MAXCHARS', 'aaaaaaaaaaaaaaaa',, 10)^ ;--- Example #2 --- #evaluate '' ^call GetIdPrepare 'PPW'^ #evaluate '' ^say GetId('PPW', '2_', '#define')^ #evaluate '' ^say GetId('PPW', '2_', '#include', '#')^ ;;Allow Hash to be valid as well