B4R Question B4R coding problem

Discussion in 'B4R Questions' started by santook, Sep 7, 2018.

  1. santook

    santook Member

    Currently, B4R USES UTF8 encoding for non-ascii characters.
    Can you add an option in the B4R IDE to allow the user to choose the encoding type? For example GB2312, utf-32, ASCII and so on.
    This is useful for some LCD applications that have a font library.
  2. Cableguy

    Cableguy Expert Licensed User

    Do remember that you can use inline C for functions that are still not available in b4r...
  3. santook

    santook Member

    I know #if c, but B4R is not a better choice if it supports optional coding options
  4. Erel

    Erel Administrator Staff Member Licensed User

    Inline C will not help here.

    You can run this B4J code to create an array of bytes with any encoding you like:
    Sub StringToArrayOfBytes(s As String, Encoding As StringAs String
    Dim sb As StringBuilder
    "Array As Byte(")
    For Each b As Byte In s.GetBytes(Encoding)
    Bit.And(0xff, b)).Append(",")
       sb.Remove(sb.Length - 
    1, sb.Length)
    Return sb.ToString
    End Sub
    Array As Byte(0,0,5,233,0,0,5,220,0,0,5,211,0,0,5,218,0,0,5,210,0,0,5,215,0,0,5,233,0,0,5,211,0,0,5,218,0,0,5,220,0,0,5,210)

    Use it instead of using a constant string.
  5. santook

    santook Member

    I know this method, I mean, it would be better to assume that B4R can provide this kind of functionality, because direct text input is more intuitive.
    Suggested methods:
    (1) an optional encoding option is provided in the IDE, and the string that starts with "" is translated into the corresponding encoding before compilation.
    (2) allow the IDE to use a special replacement blessing, such as "! # UTF8, Hello World! #!" Or "!" # ASCII, Hello World! #!"
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice