A string is a sequence of Unicode characters
- Strings are immutable objects and cannot be changed
- Create strings with single or double quotes
- Interpolate strings with ${expression} or $variable
- Concatenate strings over multiple lines
- Create multiline triple quote strings
- + will not concatenate, use String interoperation
References
Strings Examples String with out Type Annotation var s = 'single quotes'; Single quotes String s = 'single quotes'; Double quotes String s = "double quotes"; Single quote escape \' String s = 'I\'ve got single quotes'; Singe quote encapsulation "'" or "''" String s = "I've got double and single quotes"; String Interpolate String $variable interpolation String color = "grey"; String ${expression} interpolation String s = "I have ${2+3} chickens."; Multiline Strings Multiline consecutive string concatenate String s = "consecutive multiline string" ' concatenation' Multiline triple quote String s = """ Multiline single quote. String concatenate over multilines with consecutively quotes. var s = 'line 1' Raw Strings String s = @'In a raw string, even \n is ignored.'; Strings and Methods Equals String left = 'hand'; String Methods - String API String s = 'Cuthbert Musgrave Girdlestone, III'; String Buffer StringBuffer sb = new StringBuffer(); String replace, changing a multiline to single line by replacing the new line > '\n' - Try Code var multiline = "line1\nline2\nline3"; |
