Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Sybex CSG 11 - Chapter 5 Errata Page 176 Kindle Edition

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple errata on section explaining insert()
The comment result of line code 7 is wrong
should be:

actual:

 
Albert Julian Tannady
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ignore, false report. The actual is already correct. Sorry for the inconvenience
 
Marshal
Posts: 70625
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Let's look up insert(). It is heavily overloaded, but I think this version will be called. My, isn't that link easy to understand! It says inserted at the requested offset, not after it.
If k is less than offset the characters remain unchanged. So the indices 0 1 2 3 remain unchanged. Not 4.
From k = offset to k less than offset + str.length(), the character at whichever index in the argument text.
So you are correct
 
Campbell Ritchie
Marshal
Posts: 70625
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean the delimiting hyphens aren't part of the original String?
 
Albert Julian Tannady
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell,

Sorry, I should have been more clear in the first post, here is the full snippet on the book



I didn't account for the added hyphen on the fifth line. Guess I wasn't thinking clearly when I made the post.
The example is already correct, and it was my mistake when making the first post. Thanks for the reply btw!
 
Campbell Ritchie
Marshal
Posts: 70625
288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Albert Julian Tannady wrote:. . . Sorry . . . Thanks for the reply btw!

Think nothing of it. But what would happen if you reduced that code to a single line?Apart from the line being too long:-
Will that code compile? Will it run without an exception? Will it produce the same output or different output?

Line numbers don't work well inside code tags. Instead, insert the following in the first tag just before the ]

:firstline[3]

Use the preview button to verify that it has worked.
 
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic