Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1 +1,4 @@
|
|||
This task is about copying a string. Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string.
|
||||
{{omit from|bc}}
|
||||
This task is about copying a string.
|
||||
Where it is relevant, distinguish between copying the contents of a string
|
||||
versus making an additional reference to an existing string.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- String manipulation
|
||||
- Simple
|
||||
note: Basic language learning
|
||||
|
|
|
|||
4
Task/Copy-a-string/Babel/copy-a-string.pb
Normal file
4
Task/Copy-a-string/Babel/copy-a-string.pb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"Hello, world\n" dup cp
|
||||
str2ar dup 'Y' str2ar 0 paste ar2str
|
||||
<<
|
||||
<<
|
||||
|
|
@ -1,3 +1,2 @@
|
|||
src = "this is a string"
|
||||
<br><br>Note that all REXX values (variables) are stored as character strings.
|
||||
dst = src
|
||||
|
|
|
|||
9
Task/Copy-a-string/Ruby/copy-a-string-1.rb
Normal file
9
Task/Copy-a-string/Ruby/copy-a-string-1.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
original = "hello"
|
||||
reference = original # copies reference
|
||||
copy1 = original.dup # instance of original.class
|
||||
copy2 = String.new(original) # instance of String
|
||||
|
||||
original << " world!" # append
|
||||
p reference #=> "hello world!"
|
||||
p copy1 #=> "hello"
|
||||
p copy2 #=> "hello"
|
||||
7
Task/Copy-a-string/Ruby/copy-a-string-2.rb
Normal file
7
Task/Copy-a-string/Ruby/copy-a-string-2.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
original = "hello".freeze # prevents further modifications
|
||||
copy1 = original.dup # copies contents (without status)
|
||||
copy2 = original.clone # copies contents (with status)
|
||||
p copy1.frozen? #=> false
|
||||
p copy1 << " world!" #=> "hello world!"
|
||||
p copy2.frozen? #=> true
|
||||
p copy2 << " world!" #=> can't modify frozen String (RuntimeError)
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
original = "hello"
|
||||
reference = original
|
||||
copy1 = original.dup # instance of original.class
|
||||
copy2 = String.new(original) # instance of String
|
||||
6
Task/Copy-a-string/Vim-Script/copy-a-string.vim
Normal file
6
Task/Copy-a-string/Vim-Script/copy-a-string.vim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
let str1 = "original string"
|
||||
let str2 = str1
|
||||
let str1 = "new string"
|
||||
|
||||
echo "String 1:" str1
|
||||
echo "String 2:" str2
|
||||
Loading…
Add table
Add a link
Reference in a new issue