> Le 21 févr. 2019 à 22:09, Peter Mew via 4D_Tech <[email protected]> a > écrit : > > Hi > This is driving me mad, so I hope someone will point me in the right > direction. > I have a string of text. > I can find its length in Hex. now I want to write this length as 4 hex > bytes, into the string, with the aim of doing a text to blob, later on. > If I just add the Hex Number to the string it takes 8 bytes > (String+HexByte0+HexByte1+HexByte2+HexByte3) > If I convert the Hex Numbers to decimal and Do > String+char(DecByte0)+char(DecByte1) etc. > It takes up 4 Bytes but the Numbers written to the string are wrong.
Something like that? $hello:="hello world!" $len:=Length($hello) $hex:=String($len;"&x") $hex:=Substring($hex;3) $string:=$hex+$hello+"xxxxxxxxx" C_BLOB($blb) $charset:="utf-8" CONVERT FROM TEXT($string;$charset;$blb) $string2:=Convert to text($blb;$charset) $offset:=4 $hex2:=Substring($string2;1;$offset) $len2:=hexaToDecimal ($hex2) $hello2:=Substring($string2;$offset+1;$len2) ASSERT($len2=$len) ASSERT($hex2=$hex) ASSERT($hello2=$hello) -- Arnaud de Montard ********************************************************************** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:[email protected] **********************************************************************

