c# - Wait until string.contains() condition is met -
i'm reading file c# application , decompressing tile_data blob using gzip stream. i'm accessing blob data through method:
sqlitecommand command = new sqlitecommand(query, dbconn); sqlitedatareader reader = command.executereader(); bool ismet = false; while (reader.read()) { using (var file = reader.getstream(0)) using (var unzip = new gzipstream(file, compressionmode.decompress)) using (var filereader = new streamreader(unzip)) { var line = filereader.readline(); while (!filereader.endofstream) { } console.writeline("end of tile_data"); } } reader.close(); console.writeline("reader closed"); console.readkey(); } catch (exception e) { console.write(e.stacktrace); console.readkey(); }
i'm looking wait until filereader
detects "tertiary"
(string) , prints data afterwards. attempted use bool
, nested while loop
came infinite loop, hence question.
the code used (and failed with):
if (line.contains("tertiary")) { ismet = true; } while (!filereader.endofstream && ismet) { console.writeline(line); }
how can perform operation filereader
once condition has been met?
your filereader.endofstream
loop work if stream has single line. problem you're reading stream once - unless you've read whole thing, you're in endless loop.
instead, this:
string line; while ((line = filereader.readline()) != null) { if (line.contains("...")) break; // or whatever else want }
Comments
Post a Comment