Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2
|
BOOK: Beginning Java 2
This is the forum to discuss the Wrox book Beginning Java 2, SDK 1.4 Edition by Ivor Horton; ISBN: 9780764543654
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 26th, 2004, 09:24 AM
Registered User
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default chapter 4 - appending a substring

Hi,

Having trouble compiling the example of appending a substring on page 165.

The code:

StringBuffer buf = new StringBuffer("Hard ");
String aString = "Waxworks";
buf.append(aString, 3, 4);
System.out.println(buf);


gives a compile error 'cannot resolve symbol'

Any suggestions guys?

Thanks in advance.




 
Old May 27th, 2004, 03:16 AM
Authorized User
 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:
StringBuffer buf = new StringBuffer("Hard ");
String aString = "Waxworks";
buf.append(aString, 3, 4);
System.out.println(buf);

gives a compile error 'cannot resolve symbol'
http://java.sun.com/j2se/1.4.2/docs/...ingBuffer.html
at
http://java.sun.com/j2se/1.4.2/docs/api/index.html

says that no such append method exists for a StringBuffer
you should cast your String to a char array first?
and use:
append(char[] str, int offset, int len)

or first substring the String using:
substring(int beginIndex, int endIndex)

take heed:
endIndex

for a StringBuffer object you can also:
insert(int index, char[] str, int offset, int len)

note:
String as char[]

Hope that helps.
There are a lot of methods in those classes!
Best follow the book!

I will be back next week
Frans @ chapter 14
 
Old May 27th, 2004, 03:31 AM
Registered User
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks freezotic - I'll post it as an error in the book.

Alan

 
Old May 29th, 2004, 02:50 PM
Authorized User
 
Join Date: Sep 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by al_b_cnu
 Thanks freezotic - I'll post it as an error in the book.
Alan
I got a lot of errors here, but where can I post them?
- WROX has gone bust, but Wiley will republish Ivor's Java2 coming September

 
Old June 3rd, 2004, 10:06 AM
Registered User
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by freezotic
 
Quote:
quote:Originally posted by al_b_cnu
Quote:
 Thanks freezotic - I'll post it as an error in the book.
Alan
I got a lot of errors here, but where can I post them?
- WROX has gone bust, but Wiley will republish Ivor's Java2 coming September

I started from the link 'Contact us' from the home page, got a reply suggesting that I try this forum, so, you're the expert, freezotic!

 
Old June 3rd, 2004, 10:41 AM
Wrox Staff
 
Join Date: Jun 2003
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by al_b_cnu
 
Quote:
quote:Originally posted by freezotic
Quote:



I got a lot of errors here, but where can I post them?
- WROX has gone bust, but Wiley will republish Ivor's Java2 coming September

I started from the link 'Contact us' from the home page, got a reply suggesting that I try this forum, so, you're the expert, freezotic!


I'll pass this correction along to the Wrox Tech Support team.

Note that you can find the errata for a book by clicking on "Book List" on the navigation bar at the top of the page, and following the links on that book's page. Or, you can just click here: http://www.wrox.com/books/errata/076...2_errata.shtml.

New errata can be submitted to Wrox Tech Support directly by choosing "Contact Technical Support" from the Contact Us page.

Also, Ivor Horton's new book coming out this Fall is a new edition of his Beginning Java book, and will cover SDK 1.5.

Hope this helps,
David Mayhew
Wiley/Wrox Press
 
Old July 10th, 2004, 08:52 AM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code can be rewritten like this:

public class testString
{
    static StringBuffer buf = new StringBuffer("Hard ");
    static String aString = "Waxworks";

    public static void main( String args[] )
    {
        // this will append whole stuff
        buf.append(aString.toCharArray(), 0,
                             aString.toCharArray().length);
            System.out.println(buf);
    }
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
substring in c# sudhirbharti C# 1 February 21st, 2008 01:29 PM
substring-before() function. lafilip XSLT 1 July 11th, 2007 05:33 PM
SubString prasanta2expert Access VBA 1 November 17th, 2006 10:04 AM
StringBuffer - Appending a Substring Clarification nanap BOOK: Beginning Java 2, JDK 5 Edition 0 March 8th, 2006 08:28 AM
StringBuffer - Appending a Substring Clarification nanap BOOK: Beginning Java 2 0 March 8th, 2006 08:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.