(optional) non-negative integer; number of characters inserted, default is 1

opt

-

(optional) option of the form clear = true (or just clear) or clear = false

Description

•

The StringBuffer constructor returns a string buffer object. String buffers are useful for incrementally building long strings from shorter substrings. The naive approach, which repeatedly concatenates each new substring to the end of an ever-growing string, is extremely inefficient. StringBuffer provides an efficient mechanism for building strings.

•

The StringBuffer object returned by the constructor is a module with six methods: clear, append, appendf, newline, space, and value.

•

The clear method empties the buffer; an empty string buffer represents the empty string . This method is executed only for effect; no useful value is returned, and no arguments are required.

•

The append method appends its argument, which must be a Maple string, to the string that the buffer represents. The buffer itself is returned. This allows you to chain multiple calls to the append method of a given buffer in a single expression. The appendf (``append formatted'') method allows you to append formatted strings. It accepts arguments identical to those accepted by sprintf.

•

The newline method appends newlines n to the buffer. If the argument n is supplied, it inserts that many newlines, otherwise it defaults to one.

•

The space method appends spaces n to the buffer. If the argument n is supplied, it inserts that many spaces, otherwise defaults to one.

•

The value method returns the string represented by the buffer. No arguments are required, but it accepts a clear option (of type truefalse) which, if set, causes the buffer to be cleared upon returning the string value.

•

The intention is that you can build a long string in a string buffer by repeatedly calling the append method of the buffer, and then retrieve the value of the represented string, as a string, by calling the value method. The clear method simply allows you to re-use an existing string buffer to create a new long string, once you are done with its current contents.

•

StringBuffer objects operate efficiently in algorithms for which the number of calls to the append method greatly exceeds the number of calls to the value or clear methods.

Maplesoft™, a subsidiary of Cybernet Systems Co. Ltd. in Japan, is the leading provider of high-performance software tools for engineering, science, and mathematics. Its product suite reflects the philosophy that given great tools, people can do great things.