B4R Question How to combine variables and text ?

Discussion in 'B4R Questions' started by Ahmet KOÇ, Jun 15, 2019.

  1. Ahmet KOÇ

    Ahmet KOÇ Member Licensed User

    I have tried many methods. "dddd" variable, "ddddd" + variable, "ddddd" .variable ... how do I combine a string variable with text in an application.
     
  2. janderkan

    janderkan Active Member Licensed User

  3. Ahmet KOÇ

    Ahmet KOÇ Member Licensed User

    Thank you #janderkan


    Dim c As String = JoinStrings(Array As String("variable1: ", Value1, "Variable2: ", Value2))
     
    José J. Aguilar likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    In many cases it is a (common) mistake to use JoinStrings. Avoid it if you can. It consumes a lot of memory.
     
  5. Ahmet KOÇ

    Ahmet KOÇ Member Licensed User

    So what do you suggest, Erel? Is there any other way?
     
  6. bdunkleysmith

    bdunkleysmith Active Member Licensed User

    @Ahmet KOÇ

    I'd suggest it depends what you want to do with the variable c.

    Perhaps you can provide a bit more code showing or a description of what you are trying to achieve so users in this community can make suggestions.
     
    Erel and emexes like this.
  7. Ahmet KOÇ

    Ahmet KOÇ Member Licensed User

    Sub datagonder(xstop As String,xkapi As String, xkrc As String, xservis As String,xmac As String)
    Dim metin As String =JoinStrings(Array As String("stop=", xstop, "&kapi=", xkapi,"&krc=", xkrc,"&servis=",xservis))
    HttpJob.post(metin,JoinStrings(Array As String("macadres=",xmac)))
    durum=False
    End Sub

    I want to convert variables into a text with this code. It works. But standard joining operators don't work. E.g; "text" + var1 or "text" .var1 or "text" & var1 etc ...
     
  8. Mostez

    Mostez Active Member

    I faced that problem before, here is an example code for using RandomAccessFile to join anything, strings, bytes and numbers. First you just need to convert what you want to join to byte array then pass it to RandomAccessFile as code below;

    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Public Serial1 As Serial
        
    Private BC As ByteConverter
    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
        JoinStr
    End Sub

    private Sub JoinStr()
        
    Private raf As RandomAccessFile
        
    Dim String1 As String = "B4R "
        
    Dim String2 As String = "is a great "
        
    Dim String3 As String "tool"
        
    Dim MyString As String
        
    Dim AllStrings (19As Byte
        raf.Initialize(AllStrings, 
    True)
        raf.WriteBytes(String1.GetBytes, 
    0, String1.Length, raf.CurrentPosition)
        raf.WriteBytes(String2.GetBytes, 
    0, String2.Length, raf.CurrentPosition)
        raf.WriteBytes(String3.GetBytes, 
    0, String3.Length, raf.CurrentPosition)
        MyString = BC.StringFromBytes(AllStrings)
        
    Log(MyString)
    End Sub
     
Loading...
  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