perfaram Posted June 8, 2014 Share Posted June 8, 2014 Hi all ! I came across this : '?do=embed' frameborder='0' data-embedContent>> And I was wondering about reverting the created GUID to the original string. Is that possible ? I think yes, because it only uses a StringRegExpReplace, but I'm not sure how to do it Thx in advance ! PS : This may help Never forget to mark a question as resolved, this button has been purposely created :-P Link to comment Share on other sites More sharing options...
mikell Posted June 8, 2014 Share Posted June 8, 2014 $g = CreateGUIDFromString('A GUID string.') MsgBox(0, '', $g) $s = BinaryToString("0x" & StringRegExpReplace($g, "[{}-]", "")) MsgBox(0, '', $s) Func CreateGUIDFromString($sString) Return StringRegExpReplace(StringToBinary($sString) & _ "0000000000000000000000000000000000", "..(.{8})(.{4})(.{4})(.{4})(.{12}).*", "\{$1-$2-$3-$4-$5\}") EndFunc ? Link to comment Share on other sites More sharing options...
Solution UEZ Posted June 8, 2014 Solution Share Posted June 8, 2014 Try this: Func CreateStringFromGUID($sGUID) Local $sHex = StringRegExpReplace($sGUID, "[{|\-|}]", "") If @error Then Return SetError(1, 0, 0) If Mod(StringLen($sHex), 2) Then Return SetError(2, 0, 0) Local $aChars = StringRegExp($sHex, ".{2}", 3) If @error Then Return SetError(2, 0, 0) Local $i, $sReturn, $sChar For $i = 0 To UBound($aChars) - 1 If Not Int($aChars[$i]) Then ExitLoop $sReturn &= Chr(Dec($aChars[$i])) Next Return $sReturn EndFunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
perfaram Posted June 8, 2014 Author Share Posted June 8, 2014 It works, but it is heavily truncated : MsgBox(32, "", CreateStringFromGUID(CreateGUIDFromString('Some very simple string.'))) Func CreateGUIDFromString($sString) Return StringRegExpReplace(StringToBinary($sString) & "0000000000000000000000000000000000", "..(.{8})(.{4})(.{4})(.{4})(.{12}).*", "\{$1-$2-$3-$4-$5\}") EndFunc ;==>CreateGUIDFromString Func CreateStringFromGUID($sGUID) Local $sHex = StringRegExpReplace($sGUID, "[{|\-|}]", "") If @error Then Return SetError(1, 0, 0) If Mod(StringLen($sHex), 2) Then Return SetError(2, 0, 0) Local $aChars = StringRegExp($sHex, ".{2}", 3) If @error Then Return SetError(2, 0, 0) Local $i, $sReturn, $sChar For $i = 0 To UBound($aChars) - 1 If Not Int($aChars[$i]) Then ExitLoop $sReturn &= Chr(Dec($aChars[$i])) Next Return $sReturn EndFunc Will return 'Some very simple' instead of 'Some very simple string.'. Dunno if it's normal, though Never forget to mark a question as resolved, this button has been purposely created :-P Link to comment Share on other sites More sharing options...
UEZ Posted June 8, 2014 Share Posted June 8, 2014 The function is limited to 16 chars. That means the encoded GUID is truncated. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
mikell Posted June 8, 2014 Share Posted June 8, 2014 UEZ, expandcollapse popup$g = CreateGUIDFromString('A GUID string.') ;MsgBox(0, '', $g) $hTimer = TimerInit() For $i = 1 to 100 $s = CreateStringFromGUID1($g) Next $fDiff1 = TimerDiff($hTimer) ;MsgBox(0, '', $s) $hTimer = TimerInit() For $i = 1 to 100 $s = CreateStringFromGUID2($g) Next $fDiff2 = TimerDiff($hTimer) ;MsgBox(0, '', $s) MsgBox(0, '', $fDiff1 &@crlf& $fDiff2) ;============================================= Func CreateStringFromGUID1($sGUID) Local $sHex = StringRegExpReplace($sGUID, "[{}-]", "") If @error Then Return SetError(1, 0, 0) If Mod(StringLen($sHex), 2) Then Return SetError(2, 0, 0) $sReturn = BinaryToString("0x" & $sHex) Return $sReturn EndFunc Func CreateStringFromGUID2($sGUID) Local $sHex = StringRegExpReplace($sGUID, "[{|\-|}]", "") If @error Then Return SetError(1, 0, 0) If Mod(StringLen($sHex), 2) Then Return SetError(2, 0, 0) Local $aChars = StringRegExp($sHex, ".{2}", 3) If @error Then Return SetError(2, 0, 0) Local $i, $sReturn, $sChar For $i = 0 To UBound($aChars) - 1 If Not Int($aChars[$i]) Then ExitLoop $sReturn &= Chr(Dec($aChars[$i])) Next Return $sReturn EndFunc Func CreateGUIDFromString($sString) Return StringRegExpReplace(StringToBinary($sString) & _ "0000000000000000000000000000000000", "..(.{8})(.{4})(.{4})(.{4})(.{12}).*", "\{$1-$2-$3-$4-$5\}") EndFunc Link to comment Share on other sites More sharing options...
UEZ Posted June 8, 2014 Share Posted June 8, 2014 Nice mikell I hacked my version in 5 minutes together and have to leave my pc afterwards. So I had no time for optimizations. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
perfaram Posted June 9, 2014 Author Share Posted June 9, 2014 Thanks UEZ for your quick answer, and thanks mikell for the optimization Never forget to mark a question as resolved, this button has been purposely created :-P Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now