| 1 | = Appending = |
---|
| 2 | |
---|
| 3 | ''Part of'' TutorialFundamentals |
---|
| 4 | |
---|
| 5 | == Description == |
---|
| 6 | |
---|
| 7 | Shows how appending works with D dynamic strings. |
---|
| 8 | |
---|
| 9 | == Example == |
---|
| 10 | |
---|
| 11 | {{{ |
---|
| 12 | #!d |
---|
| 13 | import std.stdio; |
---|
| 14 | |
---|
| 15 | void main() { |
---|
| 16 | string s; |
---|
| 17 | writefln("Length: %d\tString: '%s'", s.length, s); |
---|
| 18 | |
---|
| 19 | s ~= "something "; |
---|
| 20 | writefln("Length: %d\tString: '%s'", s.length, s); |
---|
| 21 | |
---|
| 22 | s ~= "whatever"; |
---|
| 23 | writefln("Length: %d\tString: '%s'", s.length, s); |
---|
| 24 | } |
---|
| 25 | }}} |
---|
| 26 | |
---|
| 27 | == Output == |
---|
| 28 | {{{ |
---|
| 29 | Length: 0 String: '' |
---|
| 30 | Length: 10 String: 'something ' |
---|
| 31 | Length: 18 String: 'something whatever' |
---|
| 32 | |
---|
| 33 | }}} |
---|
| 34 | |
---|
| 35 | == Source == |
---|
| 36 | |
---|
| 37 | Based on [http://jcc_7.tripod.com/d/tutor/appending.html appending.html] by jcc7. |