Copy a string: Difference between revisions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 290: | Line 290: | ||
//"strCopy == src" is false |
//"strCopy == src" is false |
||
//"strCopy.equals(src)" is true |
//"strCopy.equals(src)" is true |
||
Instead, maybe you want to create a <code>StringBuffer</code> (mutable string) from an existing String or StringBuffer: |
|||
StringBuffer srcCopy = new StringBuffer("Hello"); |
|||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
Line 472: | Line 475: | ||
"bind s2 to a copy of the object bound to s1" |
"bind s2 to a copy of the object bound to s1" |
||
s2 := (s1 copy).</lang> |
s2 := (s1 copy).</lang> |
||
=={{header|Standard ML}}== |
|||
In Standard ML, <code>string</code>s are immutable, so you don't copy it. |
|||
Instead, maybe you want to create a <code>CharArray.array</code> (mutable string) from an existing <code>string</code>: |
|||
val src = "Hello"; |
|||
val srcCopy = CharArray.array (size src, #"x"); (* 'x' is just dummy character *) |
|||
CharArray.copyVec {src = src, dst = srcCopy, di = 0}; |
|||
src = CharArray.vector srcCopy; (* evaluates to true *) |
|||
or from another <code>CharArray.array</code>: |
|||
val srcCopy2 = CharArray.array (CharArray.length srcCopy, #"x"); (* 'x' is just dummy character *) |
|||
CharArray.copy {src = srcCopy, dst = srcCopy2, di = 0}; |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |