https://kotlinlang.org logo
#codereview
Title
# codereview
d

Dominaezzz

06/15/2019, 4:03 PM
I want to calculate the length of the longest string of characters in a string that don't contain a
\n
.
Copy code
val text = "some te\nxt about stuff\nshort"
text.split('\n').map { it.length }.max() // 14
Can I do this without creating new string objects and still be functional?
g

gildor

06/16/2019, 1:45 PM
Just use standard imperative loop and iterate on string chars and increment counter?
d

dumptruckman

06/20/2019, 6:28 PM
Out of curiosity, why?
d

Dominaezzz

06/20/2019, 6:31 PM
I just happen to be converting html tables (jsoup) to markdown for a generated KDoc. Some of the columns entries have
\n
and I need to calculate the width of the column.
u

ursus

06/22/2019, 1:51 AM
maxBy { it.lenght } gives you the longest string
44 Views