Announcement

Collapse
No announcement yet.

Join Function

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Join Function

    Please add your comments and suggestions as a Reply to this thread.





    PB/WIN - JOIN$ function

    Purpose
    Return a string consisting of all of the strings in an array, each separated by a delimiter.
    Syntax
    A$ = JOIN$(array(), {delim$ | BINARY})
    Remarks
    JOIN$ requires a delimiter string delim$ which may be any length.

    If the delimiter expression is a null (zero-length) string, no separators are inserted between the string sections. If the delimiter expression is the 3-byte value of "," (which may be expressed in your source code as the string literal ""","""), a leading and trailing double-quote is added to each string section. This ensures that the returned string contains standard, comma-delimited quoted fields that can be easily parsed.

    The array specified by array() may be any data type.

    BINARY
    If the array consists of fixed size elements ( numeric, Nul-Terminated Strings, etc.), the returned string consists of an exact memory image of the array data in internal format. If the array contains variable length data (Dynamic string, Field string), it is stored in PowerBASIC and/or Visual Basic packed string format: If a string is shorter than 65535 bytes, it starts with a 2-byte length WORD followed by the string data. Otherwise, it will start with a 2-byte value of 65535, followed by a DWORD indicating the string length, then finally the string data itself.

    The JOIN$ function is the natural complement to the PARSE statement.
    See AlsoReferencesExamples
    Code:
    FUNCTION PBMAIN
      DIM a$(2), s1$, s2$
      a$(0) = "Hello"
      a$(1) = "Power"
      a$(2) = "BASIC"
      s1$ = JOIN$(a$(),""",""")
      s2$ = JOIN$(a$(),$SPC)
    END FUNCTION
    Result
    Code:
    s1$ contains:  "Hello","Power","BASIC"
    s2$ contains:  Hello Power BASIC
    Last edited by Gary Beene; 28 Oct 2014, 09:37 PM.

  • #2
    I can only seem to get Join$() to work on scalar arrays. Is it possible to use it on multi-dimensional arrays? If yes, how?
    Thanks,
    -John

    Comment


    • #3
      Something like this?
      Code:
      #Compiler PBWin
      #Compile Exe
      #Dim All
      
      Function PBMain () As Long
        Local X,Y As Long
        Local Z As String
        Local A() As String
      
        ReDim A(10,10)
      
        For Y=0 To 9
          For X=0 To 9
          A(X,Y)=Dec$(X)+"/"+Dec$(Y)
          Next X
        Next Y
      
        Z=Join$(A(),$Spc)
        ? Z
      End Function

      Comment


      • #4
        By "scalar" do you mean "single dimension" vs. the "multi-dimension"? Or, do you mean multi-dimension array of byte, word, or dword?
        Code:
        #compile exe
        #dim all
        '
        function pbmain () as long
          local D3() as string
          local Targ as string
          dim D3(3,3)
          'populate array
          D3(0, 0) = "0,0" : D3(0, 1) = "0,1" : D3(0, 2) = "0,2" : D3(0, 3) = "0,3"
          D3(1, 0) = "1,0" : D3(1, 1) = "1,1" : D3(1, 2) = "1,2" : D3(1, 3) = "1,3"
          D3(2, 0) = "2,0" : D3(2, 1) = "2,1" : D3(2, 2) = "2,2" : D3(2, 3) = "2,3"
          D3(3, 0) = "3,0" : D3(3, 1) = "3,1" : D3(3, 2) = "3,2" : D3(3, 3) = "3,3"
          'test JOIN$
          Targ = join$(D3(), "-")
          'show resulting string
          ? Targ
        end function
        Multi-dimension string array is fine. You put no code, so can't say where your misunderstanding is.

        Cheers,
        Dale

        Comment


        • #5
          @Dale: I definitely meant "single dimension".

          @Frank: I thought I had tried that, and it failed. I just tried your code and it worked just fine, so I'll have to go back and find where I thought it didn't work, and take a closer look... I think the help could benefit from your example!

          Thanks,
          -John

          Comment


          • #6
            Seems John wants to sort in row major order rather than the default column major order. There is a description of column major order in ARRAY SORT under the heading 'Sorting a multi-dimensional array' which perhaps should have been adapted and adopted in the JOIN$ documentation.
            Rod
            "To every unsung hero in the universe
            To those who roam the skies and those who roam the earth
            To all good men of reason may they never thirst " - from "Heaven Help the Devil" by G. Lightfoot

            Comment


            • #7
              For future reference "scalar" means "non-array".
              "Not my circus, not my monkeys."

              Comment

              Working...
              X