Announcement

Collapse
No announcement yet.

Wish List

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

  • Wish List

    Create string of an array.

    A$ = JOIN$( Array(), $CRLF)

    Would be great is we could specify parameters to join a section of the array.

    A$ = JOIN$( Array(10 to 20), $CRLF)
    12
    Yes
    58.33%
    7
    No
    41.67%
    5

  • #2
    For me yes,

    but only if both indexes are optional:
    Code:
    JOIN$( Array([IdxStart [TO IdxEnd]]) [, delim])
    Regards
    Eros
    thinBasic programming language
    Win10 64bit - 8GB Ram - i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

    Comment


    • #3
      Anyhow, I think PB support would prefer an official request made at support at powerbasic dot com.
      So better to send them a mail in any case regardless what will be the results of this poll.
      thinBasic programming language
      Win10 64bit - 8GB Ram - i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

      Comment


      • #4
        Well, you should send in the NSF; it sounds pretty usable.

        But this is the kind of situation where I just write my own function make sure it's includeable so I can re-use it. (Or if I'm in a good mood, post a demo here).

        What comes to mind here is a header ...
        Code:
        FUNCTION JoinPartOfArray (s() AS STRING, delim AS STRING, _
                  OPTIONAL startsub as LONG, OPTIONAL endsub AS LONG) AS STRING 
        
         code here
        
        END FUNCTION
        If endSub not passed use UBOUND.; if startsub not passed use LBOUND.

        CALLS:
        Code:
          S$ = JoinPartOfArray (foo(),"*", 5)  ' from subscript 5 to end using * 
          S$ = JoinPartOfArray (foo(), ",", 6, 32) ' from subs 5 to 32 only using comma
         S$ = JoinPartOfArray (foo(), "|")       ' whole array (= JOIN$) using pipe
        Write once, use many

        MCM
        Last edited by Michael Mattias; 16 Jul 2008, 05:25 PM.
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          And in the meantime until that happy day...
          Code:
          #COMPILE EXE
          #DIM ALL
          
          'FUNCTION joPar() joins dynamic string arrays or parts of them
          FUNCTION joPar(arr() AS STRING, a AS LONG, b AS LONG, delim AS STRING) AS STRING
             LOCAL x, y, lod AS LONG
             LOCAL jStr AS STRING
          
             x = STRPTR(arr(a))
             y = STRPTR(arr(b))
             IF (x AND y) = 0 THEN ? "Error, invalid array type or array element": EXIT FUNCTION
          
             lod = LEN(delim)
             jStr = SPACE$(y - x + LEN(arr(b)) + (b - a + 1) * lod) 'make big enough string to hold join
             x = 1
          
             FOR y = a TO b
                MID$(jStr, x) = arr(y)       'write an arr element
                x = x + LEN(arr(y))
                MID$(jStr, x) = delim        'join it
                x = x + lod
             NEXT
             FUNCTION = LEFT$(jStr, x - (lod + 1)) 'trim excess
          END FUNCTION
          
          'FUNCTION joParF() joins fixed string arrays or parts of them. String len needs to be specified each time used.
          'In this example it is STRING * 100
          FUNCTION joParF(arr() AS STRING * 100, a AS LONG, b AS LONG, delim AS STRING) AS STRING
             LOCAL x, y, lod AS LONG
             LOCAL jStr AS STRING
          
             x = VARPTR(arr(a))
             y = VARPTR(arr(b))
             IF (x AND y) = 0 THEN ? "Error, invalid array type or array element": EXIT FUNCTION
          
             lod = LEN(delim)
             jStr = SPACE$(y - x + LEN(arr(b)) + (b - a + 1) * lod)
             x = 1
          
             FOR y = a TO b
                MID$(jStr, x) = arr(y)
                x = x + LEN(arr(y))     '<< can replace w/ x = x + 100 (whatever fixed str len is) for efficiency
                MID$(jStr, x) = delim
                x = x + lod
             NEXT
             FUNCTION = LEFT$(jStr, x - (lod + 1))
          END FUNCTION
                       
                        'join parts of arrays using functions joPar & joParF
          FUNCTION PBMAIN () AS LONG
              LOCAL a AS STRING, ii AS LONG, ip AS LONG PTR, t AS SINGLE
              DIM strArr(5000) AS STRING
              DIM strArr2(5000) AS STRING * 100
              OPEN "c:\joPar1dTest.txt" FOR OUTPUT AS #1
              
              FOR ii = 0 TO 5000
                 strArr(ii) = REPEAT$(ii, "ooo")
                 strArr2(ii) = STR$(ii) & "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
              NEXT
              t = TIMER
                                                             
               PRINT #1, joPar (strArr(),  751, 1250, $CRLF)
               PRINT #1, joParF(strArr2(), 1954, 2004, $CRLF)
               
             ? "k" & STR$(TIMER - t)
          END FUNCTION

          Comment


          • #6
            >And in the meantime until that happy day...



            Unless I have totally lost it, that's a totally different function from some kind of 'enhanced JOIN$'
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Just for the record, you do not have to change the code to deal with fixed string arrays of varying element size.

              You can use the technique demonstrated here... Single Function to process any array type (CC3/Win7+) 12-17-03

              .. and use the ARRAYATTR function to query the size of the elements.

              MCM
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Perhaps this is the reason that it is left the way it is. Each of us having a slightly different concept of how to go about it. I would have used a macro.
                I'm not sure that any of us would be more 'right' in how we go about it.

                Rod
                PS
                Poll could have used "Don't know" and/or "Don't care" as additional option(s).
                Last edited by Rodney Hicks; 18 Jul 2008, 10:02 AM. Reason: add postscript
                Rod
                I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                Comment


                • #9
                  Originally posted by Michael Mattias View Post
                  >that's a totally different function from some kind of 'enhanced JOIN$'
                  Steve Bouffe wanted to do this:
                  Code:
                  A$ = JOIN$( Array(10 to 20), $CRLF)
                  and the code I posted does this:
                  Code:
                  a = joPar(Array(), 10, 20, $CRLF)
                  That is a correct way I believe to do it. I like the MACRO idea too.
                  ____________________________________________


                  Originally posted by Michael Mattias View Post
                  Single Function to process any array type...
                  .. and use the ARRAYATTR function to query the size of the elements.
                  MCM
                  Thanks for the tip! Never used it like that before.

                  Comment


                  • #10
                    When I saw the function header, all I saw was 'a' and 'b' but I was looking for something like "start" and "end" or "first" and "last."

                    You fooled me. Fooled me good.
                    Michael Mattias
                    Tal Systems Inc. (retired)
                    Racine WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment

                    Working...
                    X