Results 1 to 5 of 5

Thread: Formatting string in Bin_To_Hex$ function

  1. #1
    Member
    Join Date
    Jan 2018
    Location
    France
    Age
    70
    Posts
    50
    Rep Power
    10

    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

    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
    11
    Rep Power
    3
    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

    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

  5. #5

    Formatting string in Bin_To_Hex$ function

    3 is IMO the best but it's not supported on anything before Python 3.6.

    2 is good but I personally prefer to put the numbers in the placeholders as it just makes it easier to track which of the parameters to format is slotting in each placeholder.

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

Posting Permissions

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