PDA

View Full Version : Formatting string in Bin_To_Hex$ function



dco045
30-12-2020, 02:45
Hello ThinBasic developpers.

May I suggest optionnal parameters to Bin_To_Hex$( string ) function ? :confused:

A number of bytes grouping , an a separator string.

Bin_To_Hex$("Hello") gives 48656C6C6F
Bin_To_Hex$("Hello" , 2 ,":") should give 4865:6C6C:6F

and if no separator string is provided a space is used as default.
Bin_To_Hex$("Hello" , 2 ) should give 4865 6C6C 6F

I think it could improve readability.


Regards

DirectuX
30-12-2020, 16:57
Hello,
it's a job for USING$ (https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?using$.htm)

chameau
30-12-2020, 19:45
Hello,
it's a job for USING$ (https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?using$.htm)

I dont believe it works for this.

Could you send example ?



Regards.

DirectuX
30-12-2020, 20:19
I dont believe it works for this.

I mean if a keyword has to be upgraded, it should be "USING$" so it can be useful for other purposes (versatility).


But you can achieve your goal with STRINSERT$ (https://www.thinbasic.com/public/products/thinBasic/help/html/strinsert$.htm):


'---Load Console Module
Uses "Console"

dim teststring as String
Dim yourstring as string

teststring = Bin_To_Hex$("Hello") 'gives 48656C6C6F

printl teststring

'Bin_To_Hex$("Hello" , 2 ,":") should give 4865:6C6C:6F

yourstring = StrInsert$(teststring,":",-4)
printl yourstring

'and if no separator string is provided a space is used as default.
'Bin_To_Hex$("Hello" , 2 ) should give 4865 6C6C 6F

yourstring = StrInsert$(teststring," ",-4)
printl yourstring

PrintL "Press a key to end program"

'---Wait for a key press
WaitKey