by Otto » Sat Jan 14, 2023 8:46 am
Dear Jimmy,
I tried
ChatGPT
:=)
Best regards and have a nice Sunday,
Otto
hi,
when "read" XLSx via Excel ActiveX i often have "Header" which are longer than 10 Sign for FIELD in DBF
those "Header" Name can be equal on SUBSTR("Headername",1,10) so i need a "Shortname"
did somebody know a Way to get a unique "Shortname" from String which is longer than 10 Sign
There are several ways to create a unique "shortname" from a string that is longer than 10 characters:
Use a hash function: You can use a hash function such as SHA-1 or MD5 to generate a unique shortname. This will ensure that even if the original strings are similar, the shortnames will be different.
Use a combination of the first and last characters: You can use the first and last characters of the original string to create a unique shortname. For example, if the original string is "abcdefghijklmnopqrstuvwxyz", the shortname could be "a-z".
Use a counter: You can add a counter to the end of the shortname to make it unique. For example, if the original string is "abcdefghijklmnopqrstuvwxyz", the first shortname could be "abcdefghij", the second could be "abcdefghik" and so on.
Use a combination of letters and numbers: You can use a combination of letters and numbers such as a timestamp to make the shortname unique.
Use a unique id generator library: You can use a library that generates unique ids, such as uuid.
Ultimately, the best approach will depend on your specific use case and requirements.
how to do this with harbour
Here's an example of how you could create a unique "shortname" from a string that is longer than 10 characters using the Harbour programming language:
Use the SUBSTR() function to get the first 10 characters of the original string:
Copy code
shortname := SUBSTR( original_string, 1, 10 )
Use the HASH() function to create a hash of the original string:
Copy code
shortname := HASH( original_string, "md5" )
Use the first and last characters of the original string:
Copy code
shortname := SUBSTR( original_string, 1, 1 ) + "-" + SUBSTR( original_string, LEN( original_string ), 1 )
Use a counter:
Copy code
static counter := 0
shortname := SUBSTR( original_string, 1, 10 ) + "-" + counter
counter += 1
Use a combination of letters and numbers:
Copy code
shortname := SUBSTR( original_string, 1, 8 ) + "_" + DATE()
Use a unique id generator library:
Copy code
shortname := UUID()
You can use any of the above approach to get a unique shortname, depending on your specific use case and requirements.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club********************************************************************