Results 1 to 5 of 5

Thread: Split and Parse

  1. #1
    Member marcuslee's Avatar
    Join Date
    Sep 2008
    Location
    Kansas, USA
    Age
    42
    Posts
    222
    Rep Power
    38

    Split and Parse

    I've been reading about these two keywords in the help file. There are differences in the descriptions, but it seems that the basic functionality is the same: Put a long string with delimiters into an array.

    What are the differences (besides that Parse has more functionality with the matrix bit)?

    What circumstances would require one over the other?




    Mark
    Last edited by marcuslee; 06-11-2010 at 21:32.

  2. #2
    Member marcuslee's Avatar
    Join Date
    Sep 2008
    Location
    Kansas, USA
    Age
    42
    Posts
    222
    Rep Power
    38
    I've been playing around with INI files. I believe the following code demonstrates that on a simple level, Split and Parse can be used in the same way.

    Uses "INI"
    
    Dim x, n As String
    Dim z(10), d(10) As String
    Dim y,v,b As Byte
    Dim iFile As String = APP_ScriptPath + "file.ini"
    
    INI_SetKey(iFile, "1", "1", "23|26|65|76|87|43|21|35|43|99")
    x = INI_GetKey(iFile, "1", "1")           
    
    y = Parse(x,z,"|") 
    v = Split(x,"|",d)
    
    n = d(3) + z(2)
            
    b = MsgBox (0,n)
    
    Which reminds me of another observation I would like to make that doesn't have anything to do with this thread ... so I will post elsewhere.


    Mark

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    It would be interesting to know if there is some possibility to use the power of Parse-functions to get a certain element/line of some text-string.

    Currently I know only how to Parse one string into a lot of small pieces seperated by some delimiter as $CRLF for example. But it always (?) creates/redims some array which I have to supply & dim in advance although sometimes I only need a certain element of that array.


    Example:

    I have some String sFileList consists of Filenames, maybe 2500 all in one string, delimited by $CRLF.

    Now to access filename(333) I have to create some dynamic string array which gets redim'med by the parse-function once, thereafter I have to get element (filename) 333 by indexing and assigning it and drop the rest of parsed string-array thereafter to garbage again since I'm only interested in filename #333 and used up lots of unnecessary time for redim & reordering the memory .

    Now I think about something like:
      
    String myFilename = ParseElement$(sFileList, 333, $CRLF)
    
    which will just pick out and assign string-element 333 (or "" if element 333 not available) to myFilename without the need to create/redim additional variables.

    Is there already some smart way to do so?
    Last edited by ReneMiner; 10-05-2013 at 03:06.
    I think there are missing some Forum-sections as beta-testing and support

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    If I understand well what you need, PARSE$ does what you need: http://www.thinbasic.com/public/prod...tml?parse$.htm

    String myFilename = Parse$(sFileList, $CRLF, 333)
    
    The only problem with PARSE$ is that it always parse the string so it is quite inefficient to repeatedly use PARSE$ especially when the string is quite big.
    In those cases, it is better to use PARSE (without $ sign) and create an array. But if you need to use it once in a while, no problem.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    OK, thanks. Now I can see the difference between Parse and Parse$
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. parse$ or parse direction
    By kryton9 in forum thinBasic General
    Replies: 10
    Last Post: 27-04-2007, 08:29

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •