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
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
********************************************************************
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
At first I simply did something like this : (there was a time I was thinking it only was 8 chars )))
function veldnaam()
Local aTemp:={} // as a sample data
AADD(aTemp,"Naam")
AADD(aTemp,"HOOFDINGVELD1")
AADD(aTemp,"HOOFDINGVELD2")
AADD(aTemp,"PRICE")
n=0
for i = 1 to len(aTemp)
cField = aTemp[i]
if len( cField ) > 7
n++
cField := substr( cField, 1, 7 - len ( alltrim( str( n, 0 ) ) ) ) + ;
padl( alltrim( str( n, 0) ), 2, "0" )
endif
aTemp[i] = cField
next
msginfo(atostr(aTemp))
return
But now, since I have to read dozens of xls regualar, I once match the fields with the headers in a xbrowse, make the dbf and read it.
also as third...
Read the first line of exel with OLE, changes the headers into the xls and save it. Then use exeltodbf function to generate the dbf
If needed one of these, I have some basic code for it