Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reverse a GUID? Fastest way?
Message
De
22/03/2008 12:28:43
 
 
À
22/03/2008 10:58:11
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01304506
Message ID:
01304570
Vues:
23
Ok, Mike,

If there are (possible) null chars in the string, we need another way
This one takes 6.6 sec for the for/next loop

Steps
(1) Convert the str to hex
(2) add a double null char (need this. vfp only adds one. maybe chr(0) is sufficient)
(3) use the wide char reverse api
(4) convert the hex string back

Here's your modified program

(ps: GuidFormat3() could be replaced with strconv(, 15) I guess)
DECLARE INTEGER UuidCreateSequential ;
	IN Rpcrt4.Dll ;
	STRING @ lcGUID


DECLARE INTEGER StringFromGUID2 ;
	IN Ole32.DLL ;
	STRING rguid, STRING @lpsz, INTEGER cchMax

LOCAL m.lcGUID
m.lcGUID = REPLICATE(CHR(0),16)
UuidCreateSequential(@m.lcGUID)
?GuidFormat3(m.lcGuid)

m.lcGuidRev = StringReverseX(m.lcGUID)

?GuidFormat3(m.lcGuidRev)
RETURN


PROCEDURE GuidFormat3
LPARAMETERS m.lcBuffer
LOCAL m.lcPK,m.i,m.lnHex,m.lnUpper,m.lnLower
m.lcPK=SPACE(0)
FOR m.i=1 TO 16
	m.lnHex = ASC(SUBSTR(m.lcBuffer,m.i,1))
	m.lnUpper = INT(m.lnHex/16)
	m.lnLower = m.lnHex - (m.lnUpper*16)
	m.lcPK = m.lcPK + SUBSTR('0123456789ABCDEF',m.lnUpper + 1,1) + ;
		SUBSTR('0123456789ABCDEF',m.lnLower + 1,1)
ENDFOR
RETURN m.lcPK

*--------------------------------------------------------------------------
#if .f.
	(1) Convert to hex
	(2) add 0x0000 (wide char terminating null char
	(3) stringreverse wide char
	(4) convert from hex to ascii
#endif
function StringReverseX(s)
	
	return strconv(StringReverseW(strconv(m.s, 15) + bintoc(0, '2s')), 16)

endfunc
*--------------------------------------------------------------------------
function StringReverseW(s) && wide char
	
	declare string  _wcsrev in msvcrt.dll as StringReverseW string
	
	return StringReverseW(m.s)
endfunc
*--------------------------------------------------------------------------
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform