Giter Club home page Giter Club logo

pro_csv's Introduction

Pro-CSV

Easy to use CSV read/write library.

List of features

  • Read at index
  • Set at index
  • Find line and column using headers
  • Insert and Append lines/columns
  • Remove lines/columns
  • Resize the table
  • Save to file

Example

Code
fn main() {
    let mut csv = pro_csv::CSV::default();
    csv.load("a;b;c;d\na;b;c;d;d;d;d;d;d;d;\n"); // csv.load_from_file("demo.csv") exist

    // Debug & Output

    println!("# Debug\n\n{:?}", csv);
    println!("\n# Out\n\n{}", csv.to_string());

    // Reading

    println!(
        "\n# Column with name\n\n{:?}",
        csv.find_columns_index_with_name("a")
    );
    println!(
        "\n# Column content\n\n{:?}",
        csv.get_all_element_of_column(csv.find_column_index_with_name("a").unwrap())
    );
    println!(
        "\n# Line with name\n\n{:?}",
        csv.find_lines_index_with_name("a")
    );
    println!(
        "\n# Line that contain something\n\n{:?}",
        csv.find_lines_index_that_contains("a")
    );
    println!(
        "\n# Line content\n\n{:?}",
        csv.get_all_element_of_line(csv.find_line_index_with_name("a").unwrap())
    );
    println!(
        "\n# Line content using contains\n\n{:?}",
        csv.get_all_element_of_line(csv.find_line_index_that_contains("a").unwrap())
    );

    println!("\n# Get at specific location\n\n{:?}", csv.get(1, 1));
    println!(
        "\n# Get at specific location with headers\n\n{:?}",
        csv.get_with_headers(0, 0)
    );

    println!("\n# Get line count\n\n{:?}", csv.get_line_count());
    println!("\n# Get column count\n\n{:?}", csv.get_column_count());

    // Insert

    println!();

    println!("# Insert line");
    csv.insert_line(0, vec![String::from("insert_line")]);
    println!("# Insert column");
    csv.insert_column(0, String::from("insert_column"));

    // Append

    println!("# Append line");
    csv.append_line(vec![String::from("append_line")]);
    println!("# Append column");
    csv.append_column(String::from("append_column"));

    println!("# Correct the size");
    csv.correct_size();

    // Set

    println!("# Set an element");
    // Tips: You can set an element out of the current table
    // it will append lines/columns until it have the good size
    csv.set(0, 0, String::from("SET"));

    // Swap

    println!("# Swap two lines");
    csv.swap_lines(0, 1).unwrap();

    println!("# Swap two columns");
    csv.swap_columns(0, 1).unwrap();

    println!("# Remove line if exist");
    csv.remove_line(0);
    println!("# Remove column column if exist");
    csv.remove_column(0);

    // Save/Write to file

    csv.save("demo.csv").unwrap();
}
Terminal OutPut
# Debug

CSV { separator: ';', buffer: [["a", "b", "c", "d"], ["a", "b", "c", "d", "d", "d", "d", "d", "d", "d"]] }

# Out

a;b;c;d;
a;b;c;d;d;d;d;d;d;d;


# Column with name

[0]

# Column content

["a", "a"]

# Line with name

[0, 1]

# Line content

["a", "b", "c", "d"]

# Get at specific location

Some("a")

# Get line count

2

# Get column count

4

# Insert line

# Insert column

# Append line

# Append column

# Correct the size

# Set an element

# Reverse two lines

# Reverse two columns
File OutPut
a;insert_column;b;c;d;append_column;;;;;;;
insert_line;SET;;;;append_column;;;;;;;
a;insert_column;b;c;d;d;d;d;d;d;d;append_column;
;append_line;;;;append_column;;;;;;;

pro_csv's People

Contributors

evisualuser avatar

Stargazers

Juanes Paz avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.