I want to calculate the length of the longest stri...
# codereview
d
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
Just use standard imperative loop and iterate on string chars and increment counter?
d
Out of curiosity, why?
d
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
maxBy { it.lenght } gives you the longest string