InStrB Replacement

  1. last week

    Aurelian N

    Nov 2 Pre-Release Testers, Xojo Pro

    I just saw this on the docs "This item has been deprecated since version 2019r2 and should no longer be used.
    Please use MemoryBlock as a replacement." while the description is simple, could we have please some examples on how translate that using MemoryBlock , I guess the docs are incomplete in many places I see deprecations but as example old code, it's little hard for new people to learn this new API thing.

    Thanks.

  2. Michel B

    Nov 2 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited last week

    The first question you should ask yourself is "do I really need InstrB ?".

    In many cases, String.IndexOf() can do.

  3. Tim S

    Nov 3 Pre-Release Testers Canterbury, UK

    In 2019r1.1, with a string known to be ASCII, I was doing such as:

    Dim  linlen, dec as integer, line, lines(), c as string
    
    line   = lines(i)
    linlen = line.LenB
    
    for  j = 1 to linlen
      c   = line.MidB (j, 1)      // Get a char
      dec = c.AscB ()             // Get its decimal value
      ...
    Next

    In 2019r2 that got changed to:

    Var   linlen, dec as integer, lines(), c as string, line as memoryblock
    
    line    = lines(i)
    linlen  = line.Size - 1
    
    for  j = 0 to linlen
      
      dec = line.Byte (j)               // Get the decimal value of a byte
      c   = Encodings.ASCII.Chr (dec)   // See what char that is
      ...
    Next

    The rest of the code in the "for j" loop was untouched.

  4. Michael D

    Nov 4 Pre-Release Testers, Xojo Pro

    The binary versions InstrB() etc are also great to work with UTF-8 text, becuase in UTF8 you are guaranteed that all characters from 0-127 are the same as in ASCII. Using the binary versions can be much faster.

  5. Karen A

    Nov 4 Pre-Release Testers

    @Michael D The binary versions InstrB() etc are also great to work with UTF-8 text, becuase in UTF8 you are guaranteed that all characters from 0-127 are the same as in ASCII. Using the binary versions can be much faster.

    Performance seems not to have been to be a big consideration in API 2 design.

    -Karen

  6. 7 days ago

    Thom M

    Nov 4 Pre-Release Testers Greater Hartford Area, CT

    @Tim S In 2019r1.1, with a string known to be ASCII, I was doing such as:

    Dim  linlen, dec as integer, line, lines(), c as string
    
    line   = lines(i)
    linlen = line.LenB
    
    for  j = 1 to linlen
      c   = line.MidB (j, 1)      // Get a char
      dec = c.AscB ()             // Get its decimal value
      ...
    Next

    In 2019r2 that got changed to:

    Var   linlen, dec as integer, lines(), c as string, line as memoryblock
    
    line    = lines(i)
    linlen  = line.Size - 1
    
    for  j = 0 to linlen
      
      dec = line.Byte (j)               // Get the decimal value of a byte
      c   = Encodings.ASCII.Chr (dec)   // See what char that is
      ...
    Next

    The rest of the code in the "for j" loop was untouched.

    Or

    Var Characters() As String = Lines(I).Split("")
    For Each C As String In Characters
      // All set
    Next

or Sign Up to reply!