While let jump lines?

Hi. this piece work fine, but when a field occupies more than one line jump. Ej. the field AKA jump and no store the Year

Content .txt info is:
Original title
Yang Jia Jiang
AKA
Duong Gia Tuong
Saving General Yang
Year
2016

while let (Some(key), Some(value)) = (lines.next(), lines.next()) {
  if key.contains("Original Title"){
      original_title = value;
  } else if key.contains("AKA") {
      aka = value;
  } else if key.contains("Year") {
      year = value;
  }
}

Any suggestion ? Thanks

Any idea like this:

 while let (Some(key) = (lines.next()) {
                        if key.contains("Original title"){
                            lines.next();
                            original_title = key;
                        } else if key.contains("AKA") {
                            lines.next();
                            aka = key;
                        } else if key.contains("Year") {
                            lines.next();
                            year = key;
                        }
                    }

You can call lines.next() inside the loop.

while let (Some(key), Some(value)) = (lines.next(), lines.next()) {
  if key.contains("Original Title"){
      original_title = value;
  } else if key.contains("AKA") {
      aka = value;
      // ignore the next line
      let _ = lines.next();
  } else if key.contains("Year") {
      year = value;
  }
}
1 Like

Ignore and Jump many fields of .txts (ej. year)

Rise of the Sea Dragon 2013/info.txt
Info txt:
original_title: Di Renjie zhi shendu longwang
aka: Di Renjie: Shen du long wang
year:

:cry:

Not work in, more than two aliases. in field AKA

Had to grab the example code from one of your previous topics, but here is a playground link with a snippet showing how I would extend the code to make it work with multiple AKAs where we would skip all but the first AKA and only store that. Hope that helps.

2 Likes

Thanks.
solution for now. :woozy_face:

                    for line in lines {
                        if line.contains("Original title") {
                            original_title = find(&reader, &line).unwrap().trim();
                        } else if line.contains("AKA") {
                            aka = find(&reader, &line).unwrap().trim();
                        } else if line.contains("Year") {
                            year = find(&reader, &line).unwrap().trim();
                        }

                    }

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.