Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
6
Task/String-append/00DESCRIPTION
Normal file
6
Task/String-append/00DESCRIPTION
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{{basic data operation}} [[Category:Simple]]
|
||||
Most languages provide a way to concatenate two string values, but some languages also provide a convenient way to append in-place to an existing string variable without referring to the variable twice.
|
||||
For this task, create a string variable equal to any text value.
|
||||
Append the string variable with another string literal in the most idiomatic way, without double reference if your language supports it.
|
||||
|
||||
Show the contents of the variable after the append operation.
|
||||
5
Task/String-append/00META.yaml
Normal file
5
Task/String-append/00META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- String manipulation
|
||||
- String manipulation
|
||||
note: Basic language learning
|
||||
6
Task/String-append/ALGOL-68/string-append.alg
Normal file
6
Task/String-append/ALGOL-68/string-append.alg
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/a68g --script #
|
||||
# -*- coding: utf-8 -*- #
|
||||
|
||||
STRING str := "12345678";
|
||||
str +:= "9!";
|
||||
print(str)
|
||||
7
Task/String-append/AWK/string-append.awk
Normal file
7
Task/String-append/AWK/string-append.awk
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# syntax: GAWK -f STRING_APPEND.AWK
|
||||
BEGIN {
|
||||
s = "foo"
|
||||
s = s "bar"
|
||||
print(s)
|
||||
exit(0)
|
||||
}
|
||||
3
Task/String-append/AutoHotkey/string-append.ahk
Normal file
3
Task/String-append/AutoHotkey/string-append.ahk
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s := "Hello, "
|
||||
s .= "world."
|
||||
MsgBox % s
|
||||
3
Task/String-append/BASIC/string-append-1.basic
Normal file
3
Task/String-append/BASIC/string-append-1.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
S$ = "Hello"
|
||||
S$ = S$ + " World!"
|
||||
PRINT S$
|
||||
4
Task/String-append/BASIC/string-append-2.basic
Normal file
4
Task/String-append/BASIC/string-append-2.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
S$="Hello"
|
||||
S$+=" World!"
|
||||
PRINT S$
|
||||
END
|
||||
9
Task/String-append/C++/string-append.cpp
Normal file
9
Task/String-append/C++/string-append.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main( ) {
|
||||
std::string greeting( "Hello" ) ;
|
||||
greeting.append( " , world!" ) ;
|
||||
std::cout << greeting << std::endl ;
|
||||
return 0 ;
|
||||
}
|
||||
25
Task/String-append/C/string-append.c
Normal file
25
Task/String-append/C/string-append.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char str[24]="Good Morning";
|
||||
char *cstr=" to all";
|
||||
char *cstr2=" !!!";
|
||||
int x=0;
|
||||
//failure when space allocated to str is insufficient.
|
||||
|
||||
if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
|
||||
{
|
||||
/* 1st method*/
|
||||
strcat(str,cstr);
|
||||
|
||||
/*2nd method*/
|
||||
x=strlen(str);
|
||||
sprintf(&str[x],"%s",cstr2);
|
||||
|
||||
printf("%s\n",str);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
8
Task/String-append/Clojure/string-append-1.clj
Normal file
8
Task/String-append/Clojure/string-append-1.clj
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
user=> (def s "app")
|
||||
#'user/s
|
||||
user=> s
|
||||
"app"
|
||||
user=> (def s (str s "end"))
|
||||
#'user/s
|
||||
user=> s
|
||||
"append"
|
||||
2
Task/String-append/Clojure/string-append-2.clj
Normal file
2
Task/String-append/Clojure/string-append-2.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
user=> (let [s "ap", s (str s "pend")] s)
|
||||
"append"
|
||||
8
Task/String-append/Common-Lisp/string-append.lisp
Normal file
8
Task/String-append/Common-Lisp/string-append.lisp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(defmacro concatenatef (s &rest strs)
|
||||
"Append additional strings to the first string in-place."
|
||||
`(setf ,s (concatenate 'string ,s ,@strs)))
|
||||
(defvar *str* "foo")
|
||||
(concatenatef *str* "bar")
|
||||
(format T "~a~%" *str*)
|
||||
(concatenatef *str* "baz" "abc" "def")
|
||||
(format T "~a~%" *str*)
|
||||
7
Task/String-append/D/string-append.d
Normal file
7
Task/String-append/D/string-append.d
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
string s = "Hello";
|
||||
s ~= " world!";
|
||||
writeln(s);
|
||||
}
|
||||
7
Task/String-append/Euphoria/string-append.euphoria
Normal file
7
Task/String-append/Euphoria/string-append.euphoria
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
sequence string = "String"
|
||||
|
||||
printf(1,"%s\n",{string})
|
||||
|
||||
string &= " is now longer\n"
|
||||
|
||||
printf(1,"%s",{string})
|
||||
2
Task/String-append/Go/string-append.go
Normal file
2
Task/String-append/Go/string-append.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
s := "foo"
|
||||
s += "bar"
|
||||
1
Task/String-append/Haskell/string-append.hs
Normal file
1
Task/String-append/Haskell/string-append.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
main = putStrLn ("Hello" ++ "World")
|
||||
5
Task/String-append/Icon/string-append.icon
Normal file
5
Task/String-append/Icon/string-append.icon
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
procedure main()
|
||||
s := "foo"
|
||||
s ||:= "bar"
|
||||
write(s)
|
||||
end
|
||||
6
Task/String-append/J/string-append.j
Normal file
6
Task/String-append/J/string-append.j
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
s=: 'new'
|
||||
s
|
||||
new
|
||||
s=: s,' value' NB. append is in-place
|
||||
s
|
||||
new value
|
||||
8
Task/String-append/Java/string-append.java
Normal file
8
Task/String-append/Java/string-append.java
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
String sa = "Hello";
|
||||
sa += ", World!";
|
||||
System.out.println(sa);
|
||||
|
||||
StringBuilder ba = new StringBuilder();
|
||||
ba.append("Hello");
|
||||
ba.append(", World!");
|
||||
System.out.println(ba.toString());
|
||||
8
Task/String-append/JavaScript/string-append.js
Normal file
8
Task/String-append/JavaScript/string-append.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
var s1 = "Hello";
|
||||
s1 += ", World!";
|
||||
print(s1);
|
||||
|
||||
var s2 = "Goodbye";
|
||||
// concat() returns the strings together, but doesn't edit existing string
|
||||
// concat can also have multiple parameters
|
||||
print(s2.concat(", World!"));
|
||||
2
Task/String-append/Julia/string-append.julia
Normal file
2
Task/String-append/Julia/string-append.julia
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
s = "Hello"
|
||||
s *= ", world!"
|
||||
4
Task/String-append/Mathematica/string-append.math
Normal file
4
Task/String-append/Mathematica/string-append.math
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(* mutable strings are not supported *)
|
||||
s1 = "testing";
|
||||
s1 = s1 <> " 123";
|
||||
s1
|
||||
3
Task/String-append/NetRexx/string-append.netrexx
Normal file
3
Task/String-append/NetRexx/string-append.netrexx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s_ = 'Hello'
|
||||
s_ = s_', world!'
|
||||
say s_
|
||||
3
Task/String-append/NewLISP/string-append.newlisp
Normal file
3
Task/String-append/NewLISP/string-append.newlisp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(setq str "foo")
|
||||
(push "bar" str -1)
|
||||
(println str)
|
||||
5
Task/String-append/OCaml/string-append.ocaml
Normal file
5
Task/String-append/OCaml/string-append.ocaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
let () =
|
||||
let s = Buffer.create 17 in
|
||||
Buffer.add_string s "Bonjour";
|
||||
Buffer.add_string s " tout le monde!";
|
||||
print_endline (Buffer.contents s)
|
||||
7
Task/String-append/Objeck/string-append.objeck
Normal file
7
Task/String-append/Objeck/string-append.objeck
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class Append {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
x := "foo";
|
||||
x->Append("bar");
|
||||
x->PrintLine();
|
||||
}
|
||||
}
|
||||
2
Task/String-append/PARI-GP/string-append.pari
Normal file
2
Task/String-append/PARI-GP/string-append.pari
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
s = "Hello";
|
||||
s = Str(s, ", world!")
|
||||
6
Task/String-append/PL-I/string-append.pli
Normal file
6
Task/String-append/PL-I/string-append.pli
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Cat: procedure options (main);
|
||||
declare s character (100) varying;
|
||||
s = 'dust ';
|
||||
s ||= 'bowl';
|
||||
put (s);
|
||||
end Cat;
|
||||
17
Task/String-append/Pascal/string-append.pascal
Normal file
17
Task/String-append/Pascal/string-append.pascal
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
program StringAppend;
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Classes
|
||||
{ you can add units after this };
|
||||
|
||||
var
|
||||
s: String = 'Hello';
|
||||
begin
|
||||
s += ' World !';
|
||||
WriteLn(S);
|
||||
ReadLn;
|
||||
end.
|
||||
3
Task/String-append/Perl-6/string-append.pl6
Normal file
3
Task/String-append/Perl-6/string-append.pl6
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
my $str = "foo";
|
||||
$str ~= "bar";
|
||||
say $str;
|
||||
3
Task/String-append/Perl/string-append.pl
Normal file
3
Task/String-append/Perl/string-append.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
my $str = 'Foo';
|
||||
$str .= 'bar';
|
||||
print $str;
|
||||
3
Task/String-append/PicoLisp/string-append.l
Normal file
3
Task/String-append/PicoLisp/string-append.l
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(setq Str1 "12345678")
|
||||
(setq Str1 (pack Str1 "9!"))
|
||||
(println Str1)
|
||||
9
Task/String-append/PureBasic/string-append.purebasic
Normal file
9
Task/String-append/PureBasic/string-append.purebasic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
S$ = "Hello"
|
||||
S$ = S$ + " Wo" ;by referencing the string twice
|
||||
S$ + "rld!" ;by referencing the string once
|
||||
If OpenConsole()
|
||||
PrintN(S$)
|
||||
|
||||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
6
Task/String-append/Python/string-append.py
Normal file
6
Task/String-append/Python/string-append.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*- #
|
||||
|
||||
str = "12345678";
|
||||
str += "9!";
|
||||
print(str)
|
||||
1
Task/String-append/README
Normal file
1
Task/String-append/README
Normal file
|
|
@ -0,0 +1 @@
|
|||
Data source: http://rosettacode.org/wiki/String_append
|
||||
3
Task/String-append/REXX/string-append-1.rexx
Normal file
3
Task/String-append/REXX/string-append-1.rexx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s='he'
|
||||
s=s'llo world!'
|
||||
Say s
|
||||
3
Task/String-append/REXX/string-append-2.rexx
Normal file
3
Task/String-append/REXX/string-append-2.rexx
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s="He"
|
||||
s=s || 'llo, World!' /*same as: s=s||'llo, World!' */
|
||||
say s
|
||||
12
Task/String-append/Racket/string-append.rkt
Normal file
12
Task/String-append/Racket/string-append.rkt
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
;there is no built-in way to set! append in racket
|
||||
(define mystr "foo")
|
||||
(set! mystr (string-append mystr " bar"))
|
||||
(displayln mystr)
|
||||
|
||||
;but you can create a quick macro to solve that problem
|
||||
(define-syntax-rule (set-append! str value)
|
||||
(set! str (string-append str value)))
|
||||
|
||||
(define mymacrostr "foo")
|
||||
(set-append! mymacrostr " bar")
|
||||
(displayln mystr)
|
||||
4
Task/String-append/Ruby/string-append.rb
Normal file
4
Task/String-append/Ruby/string-append.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
s = "Hello wo"
|
||||
s += "rld" # new string object
|
||||
s << "!" # mutates in place, same object
|
||||
puts s
|
||||
8
Task/String-append/Scala/string-append.scala
Normal file
8
Task/String-append/Scala/string-append.scala
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
var d = "Hello" // Mutables are discouraged //> d : String = Hello
|
||||
d += ", World!" // var contains a totally new re-instantiationed String
|
||||
|
||||
val s = "Hello" // Immutables are recommended //> s : String = Hello
|
||||
val s1 = s + s //> s1 : String = HelloHello
|
||||
val f2 = () => " !" //Function assigned to variable
|
||||
//> f2 : () => String = <function0>
|
||||
println(s1 + f2()); //> HelloHello !
|
||||
9
Task/String-append/Seed7/string-append.seed7
Normal file
9
Task/String-append/Seed7/string-append.seed7
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var string: str is "12345678";
|
||||
begin
|
||||
str &:= "9!";
|
||||
writeln(str);
|
||||
end func;
|
||||
4
Task/String-append/Tcl/string-append.tcl
Normal file
4
Task/String-append/Tcl/string-append.tcl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
set s "he"
|
||||
set s "${s}llo wo"; # The braces distinguish varname from text to concatenate
|
||||
append s "rld"
|
||||
puts $s
|
||||
6
Task/String-append/VBA/string-append.vba
Normal file
6
Task/String-append/VBA/string-append.vba
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Function StringAppend()
|
||||
Dim s As String
|
||||
s = "foo"
|
||||
s = s & "bar"
|
||||
Debug.Print s
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue