B4A Library [B4X] CSVParser - CSV parser and generator

Discussion in 'Additional libraries, classes and official updates' started by Erel, Oct 29, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    CSV - comma separated values format.

    The various StringUtils libraries include methods for loading and saving CSV files.

    However these methods have a few drawbacks:

    - They work with files instead of strings. This is especially problematic if the input is not UTF8 encoded.
    - As they are implemented inside a native library it is not possible to modify their behavior. Some CSV files are not 100% valid and will not work with these methods.

    CSVParser is a class that allows parsing and generating CSV strings:
    Dim parser As CSVParser
    Dim table As List = parser.Parse(File.ReadString(File.DirAssets, "1.csv"), ","False)
    For Each row() As String In table
    'work with row
    Dim s As String = parser.GenerateString(table, ",")
    File.WriteString(File.DirApp, "1.csv", s)

    Attached Files:

    Last edited: Oct 29, 2019
  2. alwaysbusy

    alwaysbusy Expert Licensed User

    Any reason it is called CLVParser instead of CSVParser (title)?
  3. vecino

    vecino Well-Known Member Licensed User

    I have thought the same. :)
  4. Erel

    Erel Administrator Staff Member Licensed User

    Too many days of vacation.

    The name is of course CSVParser (although it is also a generator...).
    scsjc, DonManfred and alwaysbusy like this.
  5. alwaysbusy

    alwaysbusy Expert Licensed User

    I wrote, some time ago, a CSV parser too and I can't recall the times I miswrote those simple three letters :D (CVS was my 'favourite') #ItIsACurse
  6. LucaMs

    LucaMs Expert Licensed User

    The real reason is that Erel (and all of us, I think) loves CLV (xCLV) :)
  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