|
Re: I'm confused by what s.length.toString.length means
|
Posted: Nov 2, 2016 11:45 PM
|
|
> On page 96 of the 3rd Edition PDF, there is this > expresssion > > def widthOfLength(s: String) = s.length.toString.length >
> My understanding is that it returns the length of passed > in string as a String instead of an Int. > > Therefore from the REPL, if I do e.g. > "Test".length.toString.length , I expect the > value 4 of type String instead of Int. > However it returns 1 as Int. > > Am I missing something?
s.length.toString.length s ="test" s.lenght = 4 s.length.toString = "4" --> this is just a string now s.length.toString.length = 1 --> lenght of string "4" is 1. if s.length.toString = "23" then then s.length.toString.length = 2 --> lenght of string "23" is 2.
|
|