Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Note that << doesn't yet work with StringBuilders. - removed.

...

Code Block
assert '\b' == '\010' //backspace
assert '\t' == '\011' //horizontal tab
assert '\n' == '\012' //linefeed
assert '\f' == '\014' //form feed
assert '\r' == '\015' //carriage return
assert '\\' == '\\' //use backslash to escape the backslash

To span multiple lines, use either triple quotes or a backslash at the end of the continuing lines to join them with the next:

...

Code Block
def sb1= new StringBuffer()
sb1 << 'abc'
sb1 << 'def' << 'ghi' //can chain two << operators
sb1.leftShift('jkl') //equivalent method name
sb1.append('mno') //alternative method name
sb1.append( ['p', 'q', 'r'] as char[] )
sb1.append( ['r', 's', 't', 'u', 'v'] as char[], 1, 3 )
assert sb1.toString() == 'abcdefghijklmnopqrstu'

Note that << doesn't yet work with StringBuilders.

If we append to a String, a StringBuffer is returned:

...