Wiki
Version 3 (modified by hopscc, 13 years ago)

--

StringBuilder

Cobra strings are immutable. To create something like a mutable string, use StringBuilder:

def visitMessage(url) as String
    sb = StringBuilder()
    sb.appendLine('Hello [.name],')
    sb.appendLine('Please visit [url].')
    s.append(' (Beware of the trolls).')    # append without newline sep
    return sb.toString

If you would like to use explicit platform varying newlines in your code, try CobraCore.newLine which returns the newline specific to the current platform such as '\n' or '\r\n':

def visitMessage(url) as String
    nl = CobraCore.newLine
    sb = StringBuilder()
    sb.append('Hello [.name],[nl]')
    sb.append('Please visit [url].[nl]')
    return sb.toString

For more information on the StringBuilder class, see  Google(C# StringBuilder)

See also: LibraryTopics