Reading a line in txt, compare and jump?

Hi, how compare a string against txt file line ??. Thanks

let reader = fs::read_to_string(filename)
                                    .expect("Except: file info.txt not exist");
            let mut lines = reader.lines();
            // skip first line "\u{feff}"
            if lines == "\u{feff}" {

error[E0369]: binary operation == cannot be applied to type std::str::Lines<'_>
--> src/
1030 | if lines == "\u{feff}" {
| ----- ^^ ---------- &str
| |
| std::str::Lines<'_>

lines is a struct that iterates over lines of reader, it doesn't make sense to compare it to a string. If you want the next line, call You can then use it, for example like this

if let Some(line) = {
    if line == "\u{feff}" {
        // ..

But if you just want to skip the first line if it's "\u{feff}", you could do something like this

let mut line =;
if line == Some("\u{feff}") {
    // set `line` to the next line instead
    line =;

Or use Peekable::next_if_eq:

let mut lines = reader.lines().peekable();

// consumes the next line only if it is equal to "\u{feff}"

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.