Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Gene Wirchenko Newsgroups: comp.lang.java.programmer Subject: StringBuilder Difficulties Date: Tue, 28 Jun 2011 17:54:38 -0700 Organization: A noiseless patient Spider Lines: 70 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="7Qrvczazr82YckO5XW8Vtw"; logging-data="12336"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/krL+iG5nhsi1d9fzhRJfrtDUsBCcFSdA=" X-Newsreader: Forte Agent 4.2/32.1118 Cancel-Lock: sha1:dbAEJPb/sHD5s0j3D/DkU74acgo= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5757 Dear Java'ers: I am working with StringBuilder now. I grant that it is faster in execution, but it is taking a bunch of my time to get it straight. I decided to change my VRString class (call-by-value-result) to VRStringB. Complications ensued. The amount of ornamentation required in my code was nasty, so I did some simplifying. How does one assign a String value to a StringBuilder variable? For the class below (before I defined .Set()), I needed cParsedWord.Value.replace( 0,cParsedWord.Value.length(),cScan.substring(xStart,xEnd)); With .Set(), I just need cParsedWord.Value.Set(cScan.substring(xStart,xEnd)); For value equality to a String value, one needs something like cParsedWord.Value.toString().equals("some value") (because without the .toString(), the comparison will fail) whereas with .equals() below, this will do it cParsedWord.equals("some value") ***** Start of Code ***** // VRStringB Class // StringBuilder Value-Result Parameter Handling // Last Modification: 2011-06-28 class VRStringB { StringBuilder Value; VRStringB() { this.Value=new StringBuilder(""); } VRStringB ( StringBuilder Init ) { this.Value=Init; } boolean equals ( String theString ) { return this.Value.toString().equals(theString); } void Set ( String theString ) { this.Value.replace(0,this.Value.length(),theString); } } ***** End of Code ***** Am I missing something about StringBuilder, or is it really this difficult to play with? It would make a lot more sense to me if StringBuilder worked more like String does. Sincerely, Gene Wirchenko