Announcement

Collapse
No announcement yet.

Parse wishlist item

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

  • Michael Mattias
    replied
    I already sent in a NFS to do exactly that. If you send one in, too there will be at least one "checkmark"

    I had a few more options I wanted, let me see if I can find the old email...yup, found it..

    1/1/05

    Gentlemen;

    New Feature Suggestion: Enhance the PARSE function.

    Currently..
    PARSE main$, array$() [, [ANY] delim$]

    . parses the string 'main$'. always parsing all delimited fields in main$, and always stores those delimited fields in array$()
    starting with the LBOUND of array$().

    I suggest adding three options:
    - Starting delimited field number to copy to array
    - Starting array element number into which the string is parsed
    - maximum number of delimited fields to copy to the array.,


    Suggested syntax

    PARSE main$ [FROM startingfieldnumber ] [FOR count], array$([starting element no]) [, [ANY] delim$]

    For example:

    PARSE main$ FROM 7 FOR 3, array$(4) , "|"

    Would take pipe-delimited fields numbers 7, 8 and 9 from main$ and store in array$(4), array$(5) and array$(6)

    What this would do is reduce the number of string-creations required. Using the current PARSE, if main$ contains 30 delimited
    fields, 30 strings are created to fill array$. If you only need 3 fields from a row of data, one is wasting the time/resources
    necessary to create 27 strings.

    Or, if you only need the first 5 fields from a long row of delimited data...

    PARSE main$ FOR 5, array$(1), ";"

    ...would fill array$(1) to array$(5) with the first five semicolon-delimited fields found in main$


    True, you could accomplish the same thing using the PARSE$ function...
    Array$(4) = PARSE$(main$, "|", 7)
    Array$(5) = PARSE$(main$, "|", 8)
    Array$(6) = PARSE$(main$, "|", 9)

    .. but because PARSE$ always reparses all the elements of main$, this results in extra parsing. With an "all-in-one" PARSE
    statement, main$ is only parsed once, and when the FOR COUNT option is specified, parsing stops when the maximum-delimited field
    number has been found.

    Another "programmer benefit" would be that the programmer could use the (more efficient) zero-lbound array, but store the fields
    with a 'field number' subscript.. for example...

    nF = PARSECOUNT (main$, $TAB)
    redim Array$(nF)
    PARSE main$, array$(1), $TAB

    It's a thought
    MCM

    Leave a comment:


  • John Gleason
    replied
    This example is like above, but uses ASCIIZ strings for automatic terminating. If your strings don't contain $NUL's, this gives results very close (or maybe identical) to PARSE a$, b$(i).

    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
        LOCAL baseMem, ii AS LONG, baseMemStr, rndStr AS STRING
        
        baseMemStr = STRING$(560000, 0)
        rndStr = "dk5t8wsy6agwikygo0h9r8whwbedkifoifg8iedyuwy373itiusjalkedktgohlhiorduir4u4reu7w326" & _
                 "y2quwsjedkjru4rueujswik4874e7u3wu47847u373wyuwajrfikruedu2w7u27u32"
        rndStr = REPEAT$(10, rndStr)
        baseMem = STRPTR(baseMemStr)
        DIM sa(1000) AS ASCIIZ * 128 AT baseMem + 128000
        PARSE rndStr, sa(), "s"
        REDIM sa(2000) AS ASCIIZ * 128 AT baseMem
        FOR ii = 997 TO 1010    'here, show a few empty, available elements first
           ? sa(ii)
        NEXT
        ? "k"
    
    END FUNCTION

    Leave a comment:


  • Richard Angell
    replied
    A similar solution, to John's but for dynamic strings.
    Code:
    #COMPILE EXE
    #DIM ALL
    FUNCTION PBMAIN () AS LONG
        LOCAL a$,i&
        i& = 1
        a$ = FORMAT$(i&,"000") + STRING$(i&,64+i&)
        FOR i& = 2 TO 5
            a$ = a$ +$CRLF + FORMAT$(i&,"000") + STRING$(i&,65+i&)
        NEXT
        DIM pa(1 TO 10) AS STRING
        DIM ta(1 TO 5) AS STRING AT VARPTR(pa(1))
        PARSE a$, ta(),$CRLF
        REDIM ta(1 TO 5) AS STRING AT VARPTR(pa(6))
        PARSE a$, ta(),$CRLF
        FOR i& = 1 TO 10
            ? pa(i&)
        NEXT
        WAITKEY$
    END FUNCTION

    Leave a comment:


  • John Gleason
    replied
    This works with array elements of fixed size. There is virtually no run-time penalty, but you need to do a little arithmetic beforehand to get "i" positioned correctly, and array sizes set. In the below example, i = 1000.

    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
        LOCAL baseMem, ii AS LONG, baseMemStr, rndStr AS STRING
        
        baseMemStr = SPACE$(560000)
        rndStr = "dk5t8wsy6agwikygo0h9r8whwbedkifoifg8iedyuwy373itiusjalkedktgohlhiorduir4u4reu7w326" & _
                 "y2quwsjedkjru4rueujswik4874e7u3wu47847u373wyuwajrfikruedu2w7u27u32"
        rndStr = REPEAT$(10, rndStr)
        baseMem = STRPTR(baseMemStr)
        DIM sa(1000) AS STRING * 128 AT baseMem + 128000
        PARSE rndStr, sa(), "s"
        REDIM sa(2000) AS STRING * 128 AT baseMem
        FOR ii = 1000 TO 1010
           ? sa(ii)
        NEXT
        ? "k"
    
    END FUNCTION

    Leave a comment:


  • Andre Smit
    started a topic Parse wishlist item

    Parse wishlist item

    How difficult would it be to implement the following:

    PARSE a$, b$(i)

    with array b$ successively filled from element i.
Working...
X