[Divunal-devel] StringBuffers/string manipulation optimization

Glyph Lefkowitz glyph@divunal.com
Sat, 26 Jun 1999 20:02:16 -0400 (EDT)


On Thu, 24 Jun 1999, James Knight wrote:

> If you instead change your code to explicitly use a StringBuffer, like so:
> 	StringBuffer s = new StringBuffer("You are ");
> 	Enumeration e = d.subject().things();
> 	if((e != null) && e.hasMoreElements())
> 	{
> 		Thing t = (Thing)e.nextElement()
> 		s.append(s).append(t.the()).append(t.name()).toString();
> 	}
> 	player.hears(s.toString());

As Dave noticed, this code is "mad buggy, yo".  It is also mad unclear.

A more correct example:
// -

StringBuffer sb = new StringBuffer("You are carrying: ");
Enumeration e = d.subject().things();
while (e!=null && e.hasMoreElements())
{
	Thing t = (Thing) e.nextElement();
	sb.append(t.the()).append(t.name()).append("\n");
}
String toHear = sb.toString();
// -

Use this example to work from until we have a more comprehensive authoring
tutorial written.