https://kotlinlang.org logo
Title
e

elect

07/13/2018, 9:54 AM
isn't there another better stlib fun instead calling
dropWhile
+
drop
?
if (file.exists())
        file.readLines()
                .dropWhile { !it.startsWith('#') }.drop(1)
d

david-wg2

07/13/2018, 10:11 AM
you could
readText
, substring on # then split on newline.. not sure if that's any better though 😬
e

elect

07/13/2018, 10:15 AM
file can be also huge, I guess it's not an option for my case
b

Bruno

07/13/2018, 10:16 AM
filter
maybe?
file.readLines().filter { !it.startsWith("#") }
you’re gonna have just the lines that don’t start with #
e

edwardwongtl

07/13/2018, 10:22 AM
He need to read from the line starts with ‘#’ and discard all lines before that. Your filter will include those unwanted lines as well
b

Bruno

07/13/2018, 10:23 AM
yes, sorry I got the questions wrongly
d

david-wg2

07/13/2018, 10:26 AM
@elect you shouldn't use
readLines()
for huge files either
it's basically the same operation
if the file is really that big i think you should just read it normally and make a boolean flag for if you have found your hashtag yet
e

elect

07/13/2018, 10:35 AM
ok, thanks
k

karelpeeters

07/13/2018, 11:03 AM
And your current
.dropWhile { ... }.drop(1)
is fine I'd say.
👍 1