Update all new Tasks

This commit is contained in:
Ingy döt Net 2015-02-20 09:02:09 -05:00
parent 00a190b0a6
commit 91df62d461
5697 changed files with 93386 additions and 804 deletions

View 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.

View file

@ -0,0 +1,5 @@
---
category:
- String manipulation
- String manipulation
note: Basic language learning

View file

@ -0,0 +1,6 @@
#!/usr/bin/a68g --script #
# -*- coding: utf-8 -*- #
STRING str := "12345678";
str +:= "9!";
print(str)

View file

@ -0,0 +1,7 @@
# syntax: GAWK -f STRING_APPEND.AWK
BEGIN {
s = "foo"
s = s "bar"
print(s)
exit(0)
}

View file

@ -0,0 +1,3 @@
s := "Hello, "
s .= "world."
MsgBox % s

View file

@ -0,0 +1,3 @@
S$ = "Hello"
S$ = S$ + " World!"
PRINT S$

View file

@ -0,0 +1,4 @@
S$="Hello"
S$+=" World!"
PRINT S$
END

View 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 ;
}

View 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;
}

View 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"

View file

@ -0,0 +1,2 @@
user=> (let [s "ap", s (str s "pend")] s)
"append"

View 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*)

View file

@ -0,0 +1,7 @@
import std.stdio;
void main() {
string s = "Hello";
s ~= " world!";
writeln(s);
}

View file

@ -0,0 +1,7 @@
sequence string = "String"
printf(1,"%s\n",{string})
string &= " is now longer\n"
printf(1,"%s",{string})

View file

@ -0,0 +1,2 @@
s := "foo"
s += "bar"

View file

@ -0,0 +1 @@
main = putStrLn ("Hello" ++ "World")

View file

@ -0,0 +1,5 @@
procedure main()
s := "foo"
s ||:= "bar"
write(s)
end

View file

@ -0,0 +1,6 @@
s=: 'new'
s
new
s=: s,' value' NB. append is in-place
s
new value

View 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());

View 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!"));

View file

@ -0,0 +1,2 @@
s = "Hello"
s *= ", world!"

View file

@ -0,0 +1,4 @@
(* mutable strings are not supported *)
s1 = "testing";
s1 = s1 <> " 123";
s1

View file

@ -0,0 +1,3 @@
s_ = 'Hello'
s_ = s_', world!'
say s_

View file

@ -0,0 +1,3 @@
(setq str "foo")
(push "bar" str -1)
(println str)

View 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)

View file

@ -0,0 +1,7 @@
class Append {
function : Main(args : String[]) ~ Nil {
x := "foo";
x->Append("bar");
x->PrintLine();
}
}

View file

@ -0,0 +1,2 @@
s = "Hello";
s = Str(s, ", world!")

View file

@ -0,0 +1,6 @@
Cat: procedure options (main);
declare s character (100) varying;
s = 'dust ';
s ||= 'bowl';
put (s);
end Cat;

View 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.

View file

@ -0,0 +1,3 @@
my $str = "foo";
$str ~= "bar";
say $str;

View file

@ -0,0 +1,3 @@
my $str = 'Foo';
$str .= 'bar';
print $str;

View file

@ -0,0 +1,3 @@
(setq Str1 "12345678")
(setq Str1 (pack Str1 "9!"))
(println Str1)

View 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

View file

@ -0,0 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
str = "12345678";
str += "9!";
print(str)

View file

@ -0,0 +1 @@
Data source: http://rosettacode.org/wiki/String_append

View file

@ -0,0 +1,3 @@
s='he'
s=s'llo world!'
Say s

View file

@ -0,0 +1,3 @@
s="He"
s=s || 'llo, World!' /*same as: s=s||'llo, World!' */
say s

View 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)

View file

@ -0,0 +1,4 @@
s = "Hello wo"
s += "rld" # new string object
s << "!" # mutates in place, same object
puts s

View 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 !

View 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;

View 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

View file

@ -0,0 +1,6 @@
Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function