Graham Kelly
Posts: 6
Nickname: gmkelly
Registered: Jul, 2010
|
|
Re: Chapter 3 page 90 length question
|
Posted: Sep 13, 2010 2:24 AM
|
|
> > def widthOfLength(s: String) = s.length.toString.length >
Not having the book immediately to hand, I can't remember the context of the code, but the code above will give you the powers of 10 of the length.
For example
val s = "Here is a sentence" val sLen = s.length val pow = sLen.toString.length
gives: sLen of 18, but a pow of 2, so if, for example, I were formatting a column of output, I would know how much space to allocate for the largest value of 's'.
|
|