Created
          January 26, 2021 04:45 
        
      - 
      
- 
        Save smeghead/c7dbba6c4c65f5cf8196a08aa4ec8166 to your computer and use it in GitHub Desktop. 
    rust-sandbox-read-csv
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | use std::env; | |
| use std::fs::File; | |
| use std::io::prelude::*; | |
| #[derive(Debug)] | |
| struct Organization<'a> { | |
| id: &'a str, | |
| name: &'a str, | |
| } | |
| fn main() { | |
| let args: Vec<String> = env::args().collect(); | |
| let filename = &args[1]; | |
| // 現在の団体シートから読み込む | |
| let mut f = File::open(filename).expect("file not found."); | |
| let mut contents = String::new(); | |
| f.read_to_string(&mut contents).expect("read error."); | |
| let mut _organizations: Vec<Organization> = Vec::new(); | |
| for line in contents.split("\n") { | |
| let cols: Vec<&str> = line.split(",").collect(); | |
| if cols.len() < 5 { | |
| continue; | |
| } | |
| if cols[2] == "" { | |
| continue; | |
| } | |
| _organizations.push(Organization{ id: cols[0], name: cols[2]}); | |
| } | |
| println!("line: {:?}", _organizations); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment