Results 1 to 4 of 4

Thread: Formatting string in Bin_To_Hex$ function

  1. #1
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    72
    Posts
    74
    Rep Power
    14

    Formatting string in Bin_To_Hex$ function

    Hello ThinBasic developpers.

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

    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

  2. #2
    Member DirectuX's Avatar
    Join Date
    Oct 2018
    Location
    France
    Posts
    417
    Rep Power
    55

    Lightbulb

    Hello,
    it's a job for USING$
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  3. #3
    Junior Member
    Join Date
    Dec 2020
    Location
    France
    Posts
    12
    Rep Power
    6
    Quote Originally Posted by DirectuX View Post
    Hello,
    it's a job for USING$
    I dont believe it works for this.

    Could you send example ?



    Regards.

  4. #4
    Member DirectuX's Avatar
    Join Date
    Oct 2018
    Location
    France
    Posts
    417
    Rep Power
    55

    Post

    Quote Originally Posted by chameau View Post
    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$:

    '---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
    
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

Similar Threads

  1. string function & loop question
    By largo_winch in forum thinBasic General
    Replies: 4
    Last Post: 26-09-2012, 17:20
  2. Problem with returning a string from a function
    By DavidMead in forum Module SDK (Power Basic version)
    Replies: 4
    Last Post: 26-11-2008, 12:51
  3. CALL keyword with function name as string expression
    By ErosOlmi in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 0
    Last Post: 07-09-2006, 16:16

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •