O'Reilly Forums: Chapter 3 - Exercise Counts Too Many Spaces - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 3 - Exercise Counts Too Many Spaces It appears the exercise on pages 89-90 counts one too many spaces

#1 User is offline   Gildren 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 20-September 13

Posted 02 December 2013 - 04:09 PM

While working on the first exercise in chapter 3 (pages 89-90) I noticed that the pop-up box does "Hello!" three times. But when the method returns a value, it says "The message length is 21." That doesn't make sense. "Hello!" is six characters, so going through the process the message length should be 18, not 21.

I've tried repeating the exercise with different numbers of times the "Hello!" text repeats itself, but it's always with one extra space more than the actual letter count. Why is that?
0

#2 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 716
  • Joined: 08-October 08
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 02 December 2013 - 04:24 PM

Looks like you're using the second edition. One of the many small things we added to the third edition is a hand-written annotation on that page that explains the result. Here's what it says:


The length is 21 because “Hello!” is six characters, plus the \n counts as another character, which gives 7 x 3 = 21.
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com
0

#3 User is offline   Gildren 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 20-September 13

Posted 16 December 2013 - 02:13 PM

View PostAndrewStellman, on 02 December 2013 - 04:24 PM, said:

Looks like you're using the second edition. One of the many small things we added to the third edition is a hand-written annotation on that page that explains the result. Here's what it says:


The length is 21 because “Hello!” is six characters, plus the \n counts as another character, which gives 7 x 3 = 21.


Thanks -- That makes more sense, I guess, though it's weird that VisualStudio counts a page break as a character. But oh well.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users