Created
November 6, 2020 10:31
-
-
Save cuongld2/888a8b78689c9f61db54ebce56979dc1 to your computer and use it in GitHub Desktop.
Rust replace string
This file contains 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
let path = Path::new("resources/graphql_queries_popular.txt"); | |
let path_new_file = Path::new("resources/graphql_generated_queries.txt"); | |
let file = File::create(path_new_file).unwrap(); | |
let mut file = LineWriter::new(file); | |
let mut reader = my_reader::BufReader::open(&path).unwrap(); | |
let mut buffer = String::new(); | |
while let Some(line) = reader.read_line(&mut buffer) { | |
use regex::{Regex,Captures}; | |
let re = Regex::new(r"first: \d+").unwrap(); | |
let mut text_for = &line; | |
for n in 1..1000{ | |
let k = re.replace(text_for.as_ref().unwrap(), |caps: &Captures| { | |
format!("first: {}", n) }); | |
file.write(k.as_ref().as_ref()); | |
} | |
} | |
file.flush().unwrap(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment