all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
3
Task/String-concatenation/0DESCRIPTION
Normal file
3
Task/String-concatenation/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{{basic data operation}}Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal.
|
||||
|
||||
To illustrate the operation, show the content of the variables.
|
||||
4
Task/String-concatenation/1META.yaml
Normal file
4
Task/String-concatenation/1META.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- String manipulation
|
||||
note: Basic language learning
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
STRING s := "hello";
|
||||
print ((s + " literal", new line));
|
||||
STRING s1 := s + " literal";
|
||||
print ((s1, new line))
|
||||
6
Task/String-concatenation/AWK/string-concatenation.awk
Normal file
6
Task/String-concatenation/AWK/string-concatenation.awk
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
BEGIN {
|
||||
s = "hello"
|
||||
print s " literal"
|
||||
s1 = s " literal"
|
||||
print s1
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package
|
||||
{
|
||||
public class Str
|
||||
{
|
||||
public static function main():void
|
||||
{
|
||||
var s:String = "hello";
|
||||
trace(s + " literal");
|
||||
var s2:String = s + " literal";
|
||||
trace(s2);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Task/String-concatenation/Ada/string-concatenation.ada
Normal file
12
Task/String-concatenation/Ada/string-concatenation.ada
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure String_Concatenation is
|
||||
S : String := "Hello";
|
||||
begin
|
||||
Put_Line (S & " literal");
|
||||
declare
|
||||
S1 : String := S & " literal";
|
||||
begin
|
||||
Put_Line (S1);
|
||||
end;
|
||||
end String_Concatenation;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
s := "hello"
|
||||
Msgbox, %s%
|
||||
s1 := s . " literal" ;the . is optional
|
||||
Msgbox, %s1%
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
s$ = "hello"
|
||||
print s$;" literal" 'or s$ + " literal"
|
||||
s2$ = s$ + " literal"
|
||||
print s2$
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
stringvar1$ = "Hello,"
|
||||
stringvar2$ = stringvar1$ + " world!"
|
||||
PRINT "Variable 1 is """ stringvar1$ """"
|
||||
PRINT "Variable 2 is """ stringvar2$ """"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
set string=Hello
|
||||
echo %string% World
|
||||
set string2=%string% World
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
"Hello ":?var1
|
||||
& "World":?var2
|
||||
& str$(!var1 !var2):?var12
|
||||
& put$("var1=" !var1 ", var2=" !var2 ", var12=" !var12 "\n")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
blsq ) "Hello, ""world!"?+
|
||||
"Hello, world!"
|
||||
10
Task/String-concatenation/C++/string-concatenation.cpp
Normal file
10
Task/String-concatenation/C++/string-concatenation.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::string s = "hello";
|
||||
std::cout << s << " literal" << std::endl;
|
||||
std::string s2 = s + " literal";
|
||||
std::cout << s2 << std::endl;
|
||||
return 0;
|
||||
}
|
||||
25
Task/String-concatenation/C/string-concatenation.c
Normal file
25
Task/String-concatenation/C/string-concatenation.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *sconcat(const char *s1, const char *s2)
|
||||
{
|
||||
char *s0 = malloc(strlen(s1)+strlen(s2)+1);
|
||||
strcpy(s0, s1);
|
||||
strcat(s0, s2);
|
||||
return s0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char *s = "hello";
|
||||
char *s2;
|
||||
|
||||
printf("%s literal\n", s);
|
||||
/* or */
|
||||
printf("%s%s\n", s, " literal");
|
||||
|
||||
s2 = sconcat(s, " literal");
|
||||
puts(s2);
|
||||
free(s2);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(def a-str "abcd")
|
||||
(println (str a-str "efgh"))
|
||||
|
||||
(def a-new-str (str a-str "efgh"))
|
||||
(println a-new-str)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(let ((s "hello"))
|
||||
(format t "~a there!~%" s)
|
||||
(let* ((s2 " there!")
|
||||
(s (concatenate 'string s s2)))
|
||||
(format t "~a~%" s)))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(defparameter *s* "hello")
|
||||
(print (concatenate 'string *s* " literal"))
|
||||
(defparameter *s1* (concatenate 'string *s* " literal"))
|
||||
(print *s1*)
|
||||
8
Task/String-concatenation/D/string-concatenation.d
Normal file
8
Task/String-concatenation/D/string-concatenation.d
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
string s = "hello";
|
||||
writeln(s ~ " world");
|
||||
auto s2 = s ~ " world";
|
||||
writeln(s2);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
var s1 := 'Hello';
|
||||
var s2 := s1 + ' World';
|
||||
|
||||
PrintLn(s1);
|
||||
PrintLn(s2);
|
||||
12
Task/String-concatenation/Delphi/string-concatenation.delphi
Normal file
12
Task/String-concatenation/Delphi/string-concatenation.delphi
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
program Concat;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
var
|
||||
s1, s2: string;
|
||||
begin
|
||||
s1 := 'Hello';
|
||||
s2 := s1 + ' literal';
|
||||
WriteLn(s1);
|
||||
WriteLn(s2);
|
||||
end.
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
//to be compiled using dylan.NET v. 11.3.1.3 or later.
|
||||
#refstdasm mscorlib.dll
|
||||
|
||||
import System
|
||||
|
||||
assembly concatex exe
|
||||
ver 1.3.0.0
|
||||
|
||||
class public auto ansi Module1
|
||||
|
||||
method public static void main()
|
||||
var s as string = "hello"
|
||||
Console::Write(s)
|
||||
Console::WriteLine(" literal")
|
||||
var s2 as string = s + " literal"
|
||||
Console::WriteLine(s2)
|
||||
end method
|
||||
|
||||
end class
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
S = "hello",
|
||||
S1 = S ++ " literal",
|
||||
io:format ("~s literal~n",[S]),
|
||||
io:format ("~s~n",[S1])
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
sequence s, s1
|
||||
s = "hello"
|
||||
puts(1, s & " literal")
|
||||
puts(1,'\n')
|
||||
s1 = s & " literal"
|
||||
print (1, s1))
|
||||
puts(1,'\n')
|
||||
|
|
@ -0,0 +1 @@
|
|||
"wake up" [ " sheeple" append print ] [ ", you sheep" append ] bi print
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fansh> a := "abc"
|
||||
abc
|
||||
fansh> b := a + "def"
|
||||
abcdef
|
||||
fansh> a
|
||||
abc
|
||||
fansh> b
|
||||
abcdef
|
||||
4
Task/String-concatenation/Forth/string-concatenation.fth
Normal file
4
Task/String-concatenation/Forth/string-concatenation.fth
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
s" hello" pad place
|
||||
pad count type
|
||||
s" there!" pad +place \ +place is called "append" on some Forths
|
||||
pad count type
|
||||
10
Task/String-concatenation/Fortran/string-concatenation.f
Normal file
10
Task/String-concatenation/Fortran/string-concatenation.f
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
program StringConcatenation
|
||||
|
||||
integer, parameter :: maxstringlength = 64
|
||||
character (maxstringlength) :: s1, s = "hello"
|
||||
|
||||
print *,s // " literal"
|
||||
s1 = trim(s) // " literal"
|
||||
print *,s1
|
||||
|
||||
end program
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DIM bestclub AS String
|
||||
DIM myconcat AS String
|
||||
bestclub = "Liverpool"
|
||||
myconcat = bestclub & " Football Club"
|
||||
21
Task/String-concatenation/Go/string-concatenation.go
Normal file
21
Task/String-concatenation/Go/string-concatenation.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// text assigned to a string variable
|
||||
s := "hello"
|
||||
|
||||
// output string variable
|
||||
fmt.Println(s)
|
||||
|
||||
// this output requested by original task descrption, although
|
||||
// not really required by current wording of task description.
|
||||
fmt.Println(s + " literal")
|
||||
|
||||
// concatenate variable and literal, assign result to another string variable
|
||||
s2 := s + " literal"
|
||||
|
||||
// output second string variable
|
||||
fmt.Println(s2)
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
"Greetings ":s;
|
||||
s"Earthlings"+puts
|
||||
s"Earthlings"+:s1;
|
||||
s1 puts
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
def s = "Greetings "
|
||||
println s + "Earthlings"
|
||||
|
||||
def s1 = s + "Earthlings"
|
||||
println s1
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import System.IO
|
||||
s = "hello"
|
||||
s1 = s ++ " literal"
|
||||
main = do putStrLn (s ++ " literal")
|
||||
putStrLn s1
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
CHARACTER s = "hello", sl*100
|
||||
|
||||
WRITE() s // " literal"
|
||||
sl = s // " literal"
|
||||
WRITE() sl
|
||||
4
Task/String-concatenation/IDL/string-concatenation.idl
Normal file
4
Task/String-concatenation/IDL/string-concatenation.idl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
s1='Hello'
|
||||
print, s1 + ' literal'
|
||||
s2=s1 + ' literal'
|
||||
print, s2
|
||||
5
Task/String-concatenation/Icon/string-concatenation.icon
Normal file
5
Task/String-concatenation/Icon/string-concatenation.icon
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
procedure main()
|
||||
s1 := "hello"
|
||||
write(s2 := s1 || " there.") # capture the reuslt for
|
||||
write(s2) # ... the 2nd write
|
||||
end
|
||||
5
Task/String-concatenation/J/string-concatenation.j
Normal file
5
Task/String-concatenation/J/string-concatenation.j
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
s1 =. 'Some '
|
||||
]s1, 'text '
|
||||
Some text
|
||||
]s2 =. s1 , 'more text!'
|
||||
Some more text!
|
||||
8
Task/String-concatenation/Java/string-concatenation.java
Normal file
8
Task/String-concatenation/Java/string-concatenation.java
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
public class Str{
|
||||
public static void main(String[] args){
|
||||
String s = "hello";
|
||||
System.out.println(s + " literal");
|
||||
String s2 = s + " literal";
|
||||
System.out.println(s2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
var s = "hello"
|
||||
print(s + " there!")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
: concat 2 compress "" join ;
|
||||
'hello " literal" concat
|
||||
17
Task/String-concatenation/Lisaac/string-concatenation.lisaac
Normal file
17
Task/String-concatenation/Lisaac/string-concatenation.lisaac
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Section Header
|
||||
|
||||
+ name := STRING_CONCATENATION;
|
||||
|
||||
Section Public
|
||||
|
||||
- main <- (
|
||||
+ sc : STRING_CONSTANT;
|
||||
+ sv : STRING;
|
||||
|
||||
sc := "Hello";
|
||||
(sc + " literal").println;
|
||||
|
||||
sv := sc + " literal";
|
||||
sv.println;
|
||||
|
||||
);
|
||||
2
Task/String-concatenation/Logo/string-concatenation.logo
Normal file
2
Task/String-concatenation/Logo/string-concatenation.logo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
make "s "hello
|
||||
print word :s "| there!|
|
||||
5
Task/String-concatenation/M4/string-concatenation.m4
Normal file
5
Task/String-concatenation/M4/string-concatenation.m4
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
define(`concat',`$1$2')dnl
|
||||
define(`A',`any text value')dnl
|
||||
concat(`A',` concatenated with string literal')
|
||||
define(`B',`concat(`A',` and string literal')')dnl
|
||||
B
|
||||
11
Task/String-concatenation/MATLAB/string-concatenation.m
Normal file
11
Task/String-concatenation/MATLAB/string-concatenation.m
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
>> string1 = '1 Fish'
|
||||
|
||||
string1 =
|
||||
|
||||
1 Fish
|
||||
|
||||
>> string2 = [string1 ', 2 Fish, Red Fish, Blue Fish']
|
||||
|
||||
string2 =
|
||||
|
||||
1 Fish, 2 Fish, Red Fish, Blue Fish
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
s = "hello"
|
||||
print (s + " literal")
|
||||
s1 = s + " literal"
|
||||
print s1
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
STRCAT
|
||||
SET S="STRING"
|
||||
WRITE !,S
|
||||
SET T=S_" LITERAL"
|
||||
WRITE !,T
|
||||
QUIT
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
str= "Hello ";
|
||||
str<>"Literal"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
s: "the quick brown fox";
|
||||
t: "jumps over the lazy dog";
|
||||
sconcat(s, " ", t);
|
||||
/* "the quick brown fox jumps over the lazy dog" */
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
:- module string_concat.
|
||||
:- interface.
|
||||
|
||||
:- import_module io.
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
:- import_module string.
|
||||
|
||||
main(!IO) :-
|
||||
S = "hello",
|
||||
S1 = S ++ " world",
|
||||
io.write_string(S, !IO), io.nl(!IO),
|
||||
io.write_string(S1, !IO), io.nl(!IO).
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
string a, b;
|
||||
a := "String";
|
||||
message a & " literal";
|
||||
b := a & " literal";
|
||||
message b;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
MODULE Concat EXPORTS Main;
|
||||
|
||||
IMPORT IO;
|
||||
|
||||
VAR string: TEXT := "String";
|
||||
string1: TEXT;
|
||||
|
||||
BEGIN
|
||||
IO.Put(string & " literal.\n");
|
||||
string1 := string & " literal.\n";
|
||||
IO.Put(string1);
|
||||
END Concat.
|
||||
|
|
@ -0,0 +1 @@
|
|||
string1 := Text.Concat(string, " literal.\n");
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Console;
|
||||
using Nemerle.Utility.NString; // contains method Concat()
|
||||
|
||||
module Stringcat
|
||||
{
|
||||
Main() : void
|
||||
{
|
||||
def text1 = "This string has";
|
||||
def cat1 = Concat( " ", [text, "been concatenated"]);
|
||||
def cat2 = text1 + " also been concatenated";
|
||||
Write($"$cat1\n$cat2\n");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
/* NetRexx */
|
||||
|
||||
options replace format comments java crossref savelog symbols
|
||||
|
||||
s1 = 'any text value'
|
||||
s2 = 'another string literal'
|
||||
s3 = s1 s2 -- concatenate variables with blank space (note that only one blank space is added)
|
||||
s4 = s1 || s2 -- concatenate variables with abuttal (here, no blank spaces are added)
|
||||
s5 = s1 'another string literal' -- concatenate a variable and a literal with blank space
|
||||
s6 = s1'another string literal' -- concatenate a variable and a literal using abuttal
|
||||
s7 = s1 || 'another string literal' -- ditto
|
||||
|
||||
say 's1:' s1 -- concatenation with blank space is employed here too
|
||||
say 's2:' s2
|
||||
say 's3:' s3
|
||||
say 's4:' s4
|
||||
say 's5:' s5
|
||||
say 's6:' s6
|
||||
say 's7:' s7
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
var str, str1 = "String"
|
||||
echo(str & " literal.")
|
||||
str1 = str1 & " literal."
|
||||
echo(str1)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
let s = "hello"
|
||||
let s1 = s ^ " literal"
|
||||
let () =
|
||||
print_endline (s ^ " literal");
|
||||
(* or Printf.printf "%s literal\n" s; *)
|
||||
print_endline s1
|
||||
11
Task/String-concatenation/Objeck/string-concatenation.objeck
Normal file
11
Task/String-concatenation/Objeck/string-concatenation.objeck
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
bundle Default {
|
||||
class Repeat {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
s := "hello";
|
||||
s->PrintLine();
|
||||
" literal"->PrintLine();
|
||||
s->Append(" literal");
|
||||
s->PrintLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Task/String-concatenation/Objective-C/string-concatenation.m
Normal file
19
Task/String-concatenation/Objective-C/string-concatenation.m
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSString *s = @"hello";
|
||||
printf("%s%s\n", [s UTF8String], " literal");
|
||||
|
||||
NSString *s2 = [s stringByAppendingString:@" literal"];
|
||||
// or, NSString *s2 = [NSString stringWithFormat:@"%@%@", s, @" literal"];
|
||||
puts([s2 UTF8String]);
|
||||
/* or */
|
||||
NSMutableString *s3 = [NSMutableString stringWithString: s];
|
||||
[s3 appendString: @" literal"];
|
||||
puts([s3 UTF8String]);
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
a="straw";
|
||||
b="berry";
|
||||
c=str(a,b); /* Concatenate a and b */
|
||||
echo (c);
|
||||
5
Task/String-concatenation/Oz/string-concatenation.oz
Normal file
5
Task/String-concatenation/Oz/string-concatenation.oz
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
declare
|
||||
S = "hello"
|
||||
{System.showInfo S#" literal"} %% virtual strings are constructed with "#"
|
||||
S1 = {Append S " literal"}
|
||||
{System.showInfo S1}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
s = "Hello ";
|
||||
s = Str(s, "world");
|
||||
\\ Alternately, this could have been:
|
||||
\\ s = concat(s, "world");
|
||||
print(s);
|
||||
6
Task/String-concatenation/PHP/string-concatenation.php
Normal file
6
Task/String-concatenation/PHP/string-concatenation.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
$s = "hello";
|
||||
echo $s . " literal" . "\n";
|
||||
$s1 = $s . " literal";
|
||||
echo $s1 . "\n";
|
||||
?>
|
||||
6
Task/String-concatenation/PL-I/string-concatenation.pli
Normal file
6
Task/String-concatenation/PL-I/string-concatenation.pli
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
declare (s, t) character (30) varying;
|
||||
|
||||
s = 'hello from me';
|
||||
display (s || ' to you.' );
|
||||
t = s || ' to you all';
|
||||
display (t);
|
||||
11
Task/String-concatenation/Pascal/string-concatenation.pascal
Normal file
11
Task/String-concatenation/Pascal/string-concatenation.pascal
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Program StringConcat;
|
||||
Var
|
||||
s, s1 : String;
|
||||
|
||||
Begin
|
||||
s := 'hello';
|
||||
writeln(s + ' literal');
|
||||
s1 := concat(s, ' literal');
|
||||
{ s1 := s + ' literal'; works too, with FreePascal }
|
||||
writeln(s1);
|
||||
End.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
my $s = 'hello';
|
||||
say $s ~ ' literal';
|
||||
my $s1 = $s ~ ' literal';
|
||||
say $s1;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$s ~= ' literal';
|
||||
say $s;
|
||||
4
Task/String-concatenation/Perl/string-concatenation-1.pl
Normal file
4
Task/String-concatenation/Perl/string-concatenation-1.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
my $s = 'hello';
|
||||
print $s . ' literal', "\n";
|
||||
my $s1 = $s . ' literal';
|
||||
print $s1, "\n";
|
||||
2
Task/String-concatenation/Perl/string-concatenation-2.pl
Normal file
2
Task/String-concatenation/Perl/string-concatenation-2.pl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$s .= ' literal';
|
||||
print $s, "\n";
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(let Str1 "First text"
|
||||
(prinl Str1 " literal")
|
||||
(let Str2 (pack Str1 " literal")
|
||||
(prinl Str2) ) )
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
$s = "Hello"
|
||||
Write-Host $s World.
|
||||
|
||||
# alternative, using variable expansion in strings
|
||||
Write-Host "$s World."
|
||||
|
||||
$s2 = $s + " World."
|
||||
Write-Host $s2
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
If OpenConsole()
|
||||
|
||||
s$ = "hello"
|
||||
PrintN( s$ + " literal")
|
||||
s2$ = s$ + " literal"
|
||||
PrintN(s2$)
|
||||
|
||||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
|
||||
Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
s1 = "hello"
|
||||
print s1 + " world"
|
||||
|
||||
s2 = s1 + " world"
|
||||
print s2
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
s1 = "hello"
|
||||
print ", ".join([s1, "world", "mom"])
|
||||
|
||||
s2 = ", ".join([s1, "world", "mom"])
|
||||
print s2
|
||||
4
Task/String-concatenation/R/string-concatenation.r
Normal file
4
Task/String-concatenation/R/string-concatenation.r
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
hello <- "hello"
|
||||
paste(hello, "literal") # "hello literal"
|
||||
hl <- paste(hello, "literal") #saves concatenates string to a new variable
|
||||
paste("no", "spaces", "between", "words", sep="") # "nospacesbetweenwords"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
s: "hello"
|
||||
print s1: rejoin [s " literal"]
|
||||
print s1
|
||||
9
Task/String-concatenation/REXX/string-concatenation.rexx
Normal file
9
Task/String-concatenation/REXX/string-concatenation.rexx
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
s = "hello"
|
||||
say s "literal"
|
||||
t = s "literal" /* Whitespace between the two strings causes a space in the output */
|
||||
say t
|
||||
|
||||
/* The above method works without spaces too */
|
||||
genus="straw"
|
||||
say genus"berry" /* This outputs strawberry */
|
||||
say genus || "berry" /* Concatenation using a doublepipe does not cause spaces */
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
with strings'
|
||||
"hello" "literal" append puts
|
||||
5
Task/String-concatenation/Ruby/string-concatenation.rb
Normal file
5
Task/String-concatenation/Ruby/string-concatenation.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
s = "hello"
|
||||
puts s + " literal"
|
||||
s1 = s + " literal"
|
||||
puts s1
|
||||
s1 << " another" # append to s1
|
||||
6
Task/String-concatenation/SAS/string-concatenation.sas
Normal file
6
Task/String-concatenation/SAS/string-concatenation.sas
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
data _null_;
|
||||
a="Hello,";
|
||||
b="World!";
|
||||
c=a !! " " !! b;
|
||||
put c;
|
||||
run;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
greet1 = "Hello, "
|
||||
output = greet1
|
||||
greet2 = greet1 "World!"
|
||||
output = greet2
|
||||
end
|
||||
8
Task/String-concatenation/Sather/string-concatenation.sa
Normal file
8
Task/String-concatenation/Sather/string-concatenation.sa
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class MAIN is
|
||||
main is
|
||||
s ::= "hello";
|
||||
#OUT + s + " literal\n";
|
||||
s2 ::= s + " literal";
|
||||
#OUT + s2 + "\n";
|
||||
end;
|
||||
end;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
val s = "hello"
|
||||
val s2 = s + " world"
|
||||
println(s2)
|
||||
6
Task/String-concatenation/Scheme/string-concatenation.ss
Normal file
6
Task/String-concatenation/Scheme/string-concatenation.ss
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(define s "hello")
|
||||
(display (string-append s " literal"))
|
||||
(newline)
|
||||
(define s1 (string-append s " literal"))
|
||||
(display s1)
|
||||
(newline)
|
||||
11
Task/String-concatenation/Seed7/string-concatenation.seed7
Normal file
11
Task/String-concatenation/Seed7/string-concatenation.seed7
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var string: s is "hello";
|
||||
var string: s2 is "";
|
||||
begin
|
||||
writeln(s <& " world");
|
||||
s2 := s & " world";
|
||||
writeln(s2);
|
||||
end func;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
define: #s -> 'hello'.
|
||||
inform: s ; ' literal'.
|
||||
define: #s1 -> (s ; ' literal').
|
||||
inform: s1.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
|s s1| s := 'hello'.
|
||||
(s,' literal') printNl.
|
||||
s1 := s,' literal'.
|
||||
s1 printNl.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
val s = "hello"
|
||||
val s1 = s ^ " literal\n"
|
||||
val () =
|
||||
print (s ^ " literal\n");
|
||||
print s1
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
"aard" → sv
|
||||
Disp sv & "vark"
|
||||
sv & "wolf" → sv2
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
$$ MODE TUSCRIPT
|
||||
s = "Hello "
|
||||
print s, "literal"
|
||||
|
||||
s1 = CONCAT (s,"literal")
|
||||
print s1
|
||||
4
Task/String-concatenation/Tcl/string-concatenation-1.tcl
Normal file
4
Task/String-concatenation/Tcl/string-concatenation-1.tcl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
set s hello
|
||||
puts "$s there!"
|
||||
append s " there!"
|
||||
puts $s
|
||||
4
Task/String-concatenation/Tcl/string-concatenation-2.tcl
Normal file
4
Task/String-concatenation/Tcl/string-concatenation-2.tcl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
set s "Hello "
|
||||
set t "World"
|
||||
set u "!"
|
||||
puts $s$t$u ;# There is nothing special here about using puts; just an example
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
%string = "Hello";
|
||||
echo(%string);
|
||||
%other = " world!";
|
||||
echo(%other);
|
||||
echo(%string @ %other);
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
s="hello"
|
||||
echo "$s literal"
|
||||
s1="$s literal" # This method only works with a space between the strings
|
||||
echo $s1
|
||||
|
||||
# To concatenate without the space we need squiggly brackets:
|
||||
genus='straw'
|
||||
fruit=${genus}berry # This outputs the word strawberry
|
||||
echo $fruit
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
echo "hello"
|
||||
| xargs -n1 -i echo {} literal
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
s = "Hello"
|
||||
Console.WriteLine(s & " literal")
|
||||
s1 = s + " literal"
|
||||
Console.WriteLine(s1)
|
||||
23
Task/String-concatenation/XPL0/string-concatenation.xpl0
Normal file
23
Task/String-concatenation/XPL0/string-concatenation.xpl0
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
func Concat(S1, S2, S3); \Concatenate strings: S3:= S1 + S2
|
||||
char S1, S2, S3;
|
||||
int C, I, J;
|
||||
[I:= 0;
|
||||
repeat C:= S1(I);
|
||||
S3(I):= C & $7F; \remove MSb terminator from first string
|
||||
I:= I+1;
|
||||
until C >= $80;
|
||||
J:= 0;
|
||||
repeat C:= S2(J);
|
||||
S3(I+J):= C;
|
||||
J:= J+1;
|
||||
until C >= $80;
|
||||
return S3;
|
||||
];
|
||||
|
||||
code Text=12;
|
||||
char A, B, C(80);
|
||||
[A:= "Hello";
|
||||
B:= " World!";
|
||||
Concat(A, B, C);
|
||||
Text(0, C);
|
||||
]
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
var1 = "Hello";
|
||||
var2 = var1 + ", world!";
|
||||
write, var1;
|
||||
write, var2;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
10 LET s$="Hello"
|
||||
20 LET s$=s$+" World!"
|
||||
30 PRINT s$
|
||||
Loading…
Add table
Add a link
Reference in a new issue