Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/String_prepend
note: Basic language learning

View file

@ -0,0 +1,17 @@
{{basic data operation}}
[[Category:String manipulation]]
[[Category: String manipulation]]
[[Category:Simple]]
{{omit from|bc|No string operations in bc}}
{{omit from|dc|No string operations in dc}}
;Task:
Create a string variable equal to any text value.
Prepend the string variable with another string literal.
If your language supports any idiomatic ways to do this without referring to the variable twice in one expression, include such solutions.
To illustrate the operation, show the content of the variable.
<br><br>

View file

@ -0,0 +1,3 @@
V s = 12345678
s = 0s
print(s)

View file

@ -0,0 +1,18 @@
* String prepend - 14/04/2020
PREPEND CSECT
USING PREPEND,13 base register
B 72(15) skip savearea
DC 17F'0' savearea
SAVE (14,12) save previous context
ST 13,4(15) link backward
ST 15,8(13) link forward
LR 13,15 set addressability
MVC C+L'B(L'A),A c=a
MVC C(L'B),B c=b+c (prepend)
XPRNT C,L'C print buffer
L 13,4(0,13) restore previous savearea pointer
RETURN (14,12),RC=0 restore registers from calling sav
A DC C'world!' a
B DC C'Hello ' b
C DC CL80' ' c
END PREPEND

View file

@ -0,0 +1,114 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program appendstr64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessString: .asciz "British Museum.\n"
szComplement: .skip 80
szStringStart: .asciz "The rosetta stone is at "
szCarriageReturn: .asciz "\n"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main:
ldr x0,qAdrszMessString // display message
bl affichageMess
ldr x0,qAdrszMessString
ldr x1,qAdrszStringStart
bl prepend // append sting2 to string1
ldr x0,qAdrszMessString
bl affichageMess
ldr x0,qAdrszCarriageReturn
bl affichageMess
100: // standard end of the program
mov x0,0 // return code
mov x8,EXIT // request to exit program
svc 0 // perform system call
qAdrszMessString: .quad szMessString
qAdrszStringStart: .quad szStringStart
qAdrszCarriageReturn: .quad szCarriageReturn
/**************************************************/
/* append two strings */
/**************************************************/
/* x0 contains the address of the string1 */
/* x1 contains the address of the string2 */
prepend:
stp x1,lr,[sp,-16]! // save registers
mov x3,#0 // length counter
1: // compute length of string 1
ldrb w4,[x0,x3]
cmp w4,#0
cinc x3,x3,ne // increment to one if not equal
bne 1b // loop if not equal
mov x5,#0 // length counter insertion string
2: // compute length of insertion string
ldrb w4,[x1,x5]
cmp x4,#0
cinc x5,x5,ne // increment to one if not equal
bne 2b
cmp x5,#0
beq 99f // string empty -> error
add x3,x3,x5 // add 2 length
add x3,x3,#1 // +1 for final zero
mov x6,x0 // save address string 1
mov x0,#0 // allocation place heap
mov x8,BRK // call system 'brk'
svc #0
mov x5,x0 // save address heap for output string
add x0,x0,x3 // reservation place x3 length
mov x8,BRK // call system 'brk'
svc #0
cmp x0,#-1 // allocation error
beq 99f
mov x4,#0 // counter byte string 2
3:
ldrb w3,[x1,x4] // load byte string 2
cbz x3,4f // zero final ?
strb w3,[x5,x4] // store byte string 2 in heap
add x4,x4,1 // increment counter 1
b 3b // no -> loop
4:
mov x2,#0 // counter byte string 1
5:
ldrb w3,[x6,x2] // load byte string 1
strb w3,[x5,x4] // store byte string in heap
cbz x3,6f // zero final ?
add x2,x2,1 // no -> increment counter 1
add x4,x4,1 // no -> increment counter 2
b 5b // no -> loop
6: // recopie heap in string 1
mov x2,#0 // counter byte string
7:
ldrb w3,[x5,x2] // load byte string in heap
strb w3,[x6,x2] // store byte string 1
cbz x3,100f // zero final ?
add x2,x2,1 // no -> increment counter 1
b 7b // no -> loop
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

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

View file

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

View file

@ -0,0 +1,39 @@
PROC Append(CHAR ARRAY text,suffix)
BYTE POINTER srcPtr,dstPtr
BYTE len
len=suffix(0)
IF text(0)+len>255 THEN
len=255-text(0)
FI
IF len THEN
srcPtr=suffix+1
dstPtr=text+text(0)+1
MoveBlock(dstPtr,srcPtr,len)
text(0)==+suffix(0)
FI
RETURN
PROC Prepend(CHAR ARRAY text,prefix)
CHAR ARRAY tmp(256)
SCopy(tmp,text)
SCopy(text,prefix)
Append(text,tmp)
RETURN
PROC TestPrepend(CHAR ARRAY text,preffix)
PrintF("Source ""%S"" at address %H%E",text,text)
PrintF("Prepend ""%S""%E",preffix)
Prepend(text,preffix)
PrintF("Result ""%S"" at address %H%E",text,text)
PutE()
RETURN
PROC Main()
CHAR ARRAY text(256)
text(0)=0
TestPrepend(text,"World!")
TestPrepend(text,"Hello ")
RETURN

View file

@ -0,0 +1,8 @@
with Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
procedure Prepend_String is
S: Unbounded_String := To_Unbounded_String("World!");
begin
S := "Hello " & S;-- this is the operation to prepend "Hello " to S.
Ada.Text_IO.Put_Line(To_String(S));
end Prepend_String;

View file

@ -0,0 +1,3 @@
set aVariable to "world!"
set aVariable to "Hello " & aVariable
return aVariable

View file

@ -0,0 +1 @@
"Hello world!"

View file

@ -0,0 +1,17 @@
use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
set aVariable to current application's class "NSString"'s stringWithString:("world!")
set aVariable to aVariable's stringByReplacingCharactersInRange:({0, 0}) withString:("Hello ")
-- return aVariable as text
-- Or:
set aVariable to current application's class "NSString"'s stringWithString:("world!")
set aVariable to current application's class "NSString"'s stringWithFormat_("%@%@", "Hello ", aVariable)
-- return aVariable as text
-- Or:
set aVariable to current application's class "NSString"'s stringWithString:("world!")
set aVariable to aVariable's stringByReplacingOccurrencesOfString:("^") withString:("Hello ") ¬
options:(current application's NSRegularExpressionSearch) range:({0, 0})
-- return aVariable as text

View file

@ -0,0 +1,6 @@
use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
set aVariable to current application's class "NSMutableString"'s stringWithString:("world!")
tell aVariable to insertString:("Hello ") atIndex:(0)
return aVariable as text

View file

@ -0,0 +1 @@
"Hello world!"

View file

@ -0,0 +1,3 @@
100 LET S$=" World!"
110 LET S$="Hello"+S$
120 PRINT S$

View file

@ -0,0 +1,14 @@
a: "World"
a: "Hello" ++ a
print a
b: "World"
b: append "Hello" b
print a
c: "World"
prefix 'c "Hello"
print c
d: "World"
print prefix d "Hello"

View file

@ -0,0 +1,5 @@
string s1 = " World!";
write("Hello" + s1);
write("Hello", s1);
string s2 = "Hello" + s1;
write(s2);

View file

@ -0,0 +1,3 @@
s := "foo"
s := s "bar"
Msgbox % s

View file

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

View file

@ -0,0 +1,8 @@
a$ = " World!"
a$ = "Hello"; a$
print a$
# would also be valid
a$ = "Hello" + a$
# and
a$ = "Hello" & a$

View file

@ -0,0 +1,3 @@
s$ = "prepend"
s$ = "String " & s$
PRINT s$

View file

@ -0,0 +1,3 @@
World!:?string
& str$("Hello " !string):?string
& out$!string

View file

@ -0,0 +1,13 @@
include <vector>
#include <algorithm>
#include <string>
#include <iostream>
int main( ) {
std::vector<std::string> myStrings { "prepended to" , "my string" } ;
std::string prepended = std::accumulate( myStrings.begin( ) ,
myStrings.end( ) , std::string( "" ) , []( std::string a ,
std::string b ) { return a + b ; } ) ;
std::cout << prepended << std::endl ;
return 0 ;
}

View file

@ -0,0 +1,15 @@
using System;
namespace PrependString
{
class Program
{
static void Main(string[] args)
{
string str = "World";
str = "Hello " + str;
Console.WriteLine(str);
Console.ReadKey();
}
}
}

View file

@ -0,0 +1,14 @@
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char str[100]="my String";
char *cstr="Changed ";
char *dup;
sprintf(str,"%s%s",cstr,(dup=strdup(str)));
free(dup);
printf("%s\n",str);
return 0;
}

View file

@ -0,0 +1,25 @@
identification division.
program-id. prepend.
data division.
working-storage section.
1 str pic x(30) value "World!".
1 binary.
2 len pic 9(4) value 0.
2 scratch pic 9(4) value 0.
procedure division.
begin.
perform rev-sub-str
move function reverse ("Hello ") to str (len + 1:)
perform rev-sub-str
display str
stop run
.
rev-sub-str.
move 0 to len scratch
inspect function reverse (str)
tallying scratch for leading spaces
len for characters after space
move function reverse (str (1:len)) to str
.
end program prepend.

View file

@ -0,0 +1,12 @@
>>SOURCE FREE
PROGRAM-ID. prepend.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 str PIC X(30) VALUE "world!".
PROCEDURE DIVISION.
MOVE FUNCTION CONCATENATE("Hello, ", str) TO str
DISPLAY str
.
END PROGRAM prepend.

View file

@ -0,0 +1,2 @@
(defn str-prepend [a-string, to-prepend]
(str to-prepend a-string))

View file

@ -0,0 +1,5 @@
(def s (atom "World"))
(swap! s #(str "Hello, " %))
user=> @s
user=> "Hello, Wolrd"

View file

@ -0,0 +1,5 @@
(def s (ref "World"))
(dosync (alter s #(str "Hello " %)))
user=> @s
user=> "Hello World"

View file

@ -0,0 +1,4 @@
<cfoutput>
<cfset who = "World!">
#"Hello " & who#
</cfoutput>

View file

@ -0,0 +1,5 @@
<cfscript>
who = "World!";
greeting = "Hello " & who;
writeOutput( greeting );
</cfscript>

View file

@ -0,0 +1,7 @@
(defmacro prependf (s &rest strs)
"Prepend the given string variable with additional strings. The string variable is modified in-place."
`(setf ,s (concatenate 'string ,@strs ,s)))
(defvar *str* "foo")
(prependf *str* "bar")
(format T "~a~%" *str*)

View file

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

View file

@ -0,0 +1,38 @@
program String_preappend;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
type
TStringHelper = record helper for string
procedure Preappend(str: string);
end;
{ TStringHelper }
procedure TStringHelper.Preappend(str: string);
begin
Self := str + self;
end;
begin
var h: string;
// with + operator
h := 'World';
h := 'Hello ' + h;
writeln(h);
// with a function concat
h := 'World';
h := concat('Hello ', h);
writeln(h);
// with helper
h := 'World';
h.Preappend('Hello ');
writeln(h);
readln;
end.

View file

@ -0,0 +1,3 @@
var s = "world!"
s = "Hello " + s
print(s)

View file

@ -0,0 +1,5 @@
......
S$=" World!"
S$="Hello"+S$
PRINT(S$)
......

View file

@ -0,0 +1,3 @@
string$ = "Lang"
string$ = "Easy" & string$
print string$

View file

@ -0,0 +1,10 @@
define-syntax-rule
(set!-string-prepend a before)
(set! a (string-append before a)))
→ #syntax:set!-string-prepend
(define name "Presley")
→ name
(set!-string-prepend name "Elvis ")
name
→ "Elvis Presley"

View file

@ -0,0 +1,15 @@
import extensions;
import extensions'text;
public program()
{
var s := "World";
s := "Hello " + s;
console.writeLine:s;
// Alternative way
var s2 := StringWriter.load("World");
s2.insert(0, "Hello ");
console.writeLine:s2;
console.readChar()
}

View file

@ -0,0 +1,2 @@
str1 = "World!"
str = "Hello, " <> str1

View file

@ -0,0 +1,3 @@
(defvar str "bar")
(setq str (concat "foo" str))
str ;=> "foobar"

View file

@ -0,0 +1,5 @@
(require 'cl-lib)
(defvar str "bar")
(cl-callf2 concat "foo" str)
str ;=> "foobar"

View file

@ -0,0 +1,8 @@
(let ((buf (get-buffer-create "*foo*")))
(with-current-buffer buf
(insert "bar"))
(with-current-buffer buf
(goto-char (point-min))
(insert "foo")
(buffer-string)))
;; => "foobar"

View file

@ -0,0 +1,3 @@
let mutable s = "world!"
s <- "Hello, " + s
printfn "%s" s

View file

@ -0,0 +1,2 @@
"world"
"Hello " prepend

View file

@ -0,0 +1,7 @@
/* created by Aykayayciti Earl Lamont Montgomery
April 9th, 2018 */
s = "fun "
s = s + "Falcon"
> s

View file

@ -0,0 +1,19 @@
\ the following functions are commonly native to a Forth system. Shown for completeness
: C+! ( n addr -- ) dup c@ rot + swap c! ; \ primitive: increment a byte at addr by n
: +PLACE ( addr1 length addr2 -- ) \ Append addr1 length to addr2
2dup 2>r count + swap move 2r> c+! ;
: PLACE ( addr1 len addr2 -- ) \ addr1 and length, placed at addr2 as counted string
2dup 2>r 1+ swap move 2r> c! ;
\ Example begins here
: PREPEND ( addr len addr2 -- addr2)
>R \ push addr2 to return stack
PAD PLACE \ place the 1st string in PAD
R@ count PAD +PLACE \ append PAD with addr2 string
PAD count R@ PLACE \ move the whole thing back into addr2
R> ; \ leave a copy of addr2 on the data stack
: writeln ( addr -- ) cr count type ; \ syntax sugar for testing

View file

@ -0,0 +1,15 @@
INTEGER*4 I,TEXT(66)
DATA TEXT(1),TEXT(2),TEXT(3)/"Wo","rl","d!"/
WRITE (6,1) (TEXT(I), I = 1,3)
1 FORMAT ("Hello ",66A2)
DO 2 I = 1,3
2 TEXT(I + 3) = TEXT(I)
TEXT(1) = "He"
TEXT(2) = "ll"
TEXT(3) = "o "
WRITE (6,3) (TEXT(I), I = 1,6)
3 FORMAT (66A2)
END

View file

@ -0,0 +1,5 @@
CHARACTER*66 TEXT
TEXT = "World!"
TEXT = "Hello "//TEXT
WRITE (6,*) TEXT
END

View file

@ -0,0 +1,8 @@
var
line: string[20];
begin
line := 'Hello ';
{$COperators on}
line += 'world!';
writeLn(line)
end.

View file

@ -0,0 +1,6 @@
' FB 1.05.0 Win64
Var s = "prepend"
s = "String " + s
Print s
Sleep

View file

@ -0,0 +1,11 @@
include "NSLog.incl"
void local fn DoIt
CFStringRef s = @"world!"
s = fn StringByAppendingString( @"Hello ", s )
NSLog(@"%@",s)
end fn
fn DoIt
HandleEvents

View file

@ -0,0 +1,9 @@
Public Sub Main()
Dim sString1 As String = "world!"
Dim sString2 As String = "Hello "
sString1 = sString2 & sString1
Print sString1
End

View file

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

View file

@ -0,0 +1,2 @@
Prelude> let f = (++" World!")
Prelude> f "Hello"

View file

@ -0,0 +1,3 @@
100 LET S$=" World!"
110 LET S$="Hello"&S$
120 PRINT S$

View file

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

View file

@ -0,0 +1,5 @@
procedure main()
s := ", world"
s[1:1] ||:= "Hello"
write(s)
end

View file

@ -0,0 +1,4 @@
procedure main()
(s := ", world") ?:= "Hello" || tab(0)
write(s)
end

View file

@ -0,0 +1,6 @@
s=: 'value'
s
value
s=: 'new ',s
s
new value

View file

@ -0,0 +1,2 @@
String string = "def";
string = "abc" + string;

View file

@ -0,0 +1,2 @@
String string = "def";
string = "abc".concat(string);

View file

@ -0,0 +1,3 @@
StringBuilder string = new StringBuilder();
string.append("def");
string.insert(0, "abc");

View file

@ -0,0 +1,2 @@
String string = "def";
string = String.format("abc%s", string);

View file

@ -0,0 +1,2 @@
String string = "def";
string = "abc%s".formatted(string);

View file

@ -0,0 +1,4 @@
// No built-in prepend
var s=", World"
s = "Hello" + s
print(s);

View file

@ -0,0 +1,2 @@
"world!" as $s
| "Hello " + $s

View file

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

View file

@ -0,0 +1,4 @@
s: "world!"
"world!"
"Hello " , s
"Hello world!"

View file

@ -0,0 +1,13 @@
// version 1.0.6
fun main(args: Array<String>) {
var s = "Obama"
s = "Barack " + s
println(s)
// It's also possible to use this standard library function
// though this is not what it's really intended for
var t = "Trump"
t = t.prependIndent("Donald ")
println(t)
}

View file

@ -0,0 +1,4 @@
> (set s "world")
"world"
> (++ "hello " s)
"hello world"

View file

@ -0,0 +1,4 @@
> (set s "world")
"world"
> (string:concat "hello " s)
"hello world"

View file

@ -0,0 +1,5 @@
{def str World}
-> str
Hello, {str}
-> Hello, World

View file

@ -0,0 +1,3 @@
local(x = ', World!')
#x->merge(1,'Hello')
#x // Hello, World!

View file

@ -0,0 +1,4 @@
str = "world!"
put "Hello " before str
put str
-- "Hello world!"

View file

@ -0,0 +1,3 @@
put "world" into x
put "hello" before x
put x // hello world

View file

@ -0,0 +1,3 @@
s = "12345678"
s = "0" .. s
print(s)

View file

@ -0,0 +1,3 @@
s = "12345678"
s = string.format("%s%s", "0", s)
print(s)

View file

@ -0,0 +1,3 @@
s = "12345678"
s = table.concat({"0", s})
print(s)

View file

@ -0,0 +1,6 @@
Module PrependString {
A$="Hello"
A$+=" World"
Print A$
}
PrependString

View file

@ -0,0 +1,4 @@
l := " World";
m := cat("Hello", l);
n := "Hello"||l;
o := `||`("Hello", l);

View file

@ -0,0 +1,2 @@
a = "any text value";
a = "another string literal" <> a (* using concatenation (no built-in prepend) *)

View file

@ -0,0 +1,9 @@
:- module string_prepend.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module string.
main(!IO) :-
S = "World!\n",
io.write_string("Hello " ++ S, !IO).

View file

@ -0,0 +1,4 @@
s1 = " a test"
s1 = "this is" + s1
println s1

View file

@ -0,0 +1,7 @@
/**
<doc><p>String prepend in Neko</pre></doc>
**/
var str = ", world"
str = "Hello" + str
$print(str, "\n")

View file

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

View file

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

View file

@ -0,0 +1,8 @@
# Direct way.
var str1, str2 = "12345678"
str1 = "0" & str1
echo str1
# Using "insert".
str2.insert("0")
echo str2

View file

@ -0,0 +1,4 @@
let () =
let s = ", world" in
let s = "Hello" ^ s in
print_endline s

View file

@ -0,0 +1,6 @@
class Prepend {
function : Main(args : String[]) ~ Nil {
s := "world!";
"Hello {$s}"->PrintLine();
}
}

View file

@ -0,0 +1 @@
" World" "Hello" swap + println

View file

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

View file

@ -0,0 +1,6 @@
Pre_Cat: procedure options (main); /* 2 November 2013 */
declare s character (100) varying;
s = ' bowl';
s = 'dust' || s;
put (s);
end Pre_Cat;

View file

@ -0,0 +1,12 @@
program stringPrepend(output);
var
line: string(20);
begin
line := 'Hello ';
line := line + 'world!';
writeLn(line);
line := 'Hello ';
writeStr(line, line, 'world!');
writeLn(line)
end.

View file

@ -0,0 +1,21 @@
use strict;
use warnings;
use feature ':all';
# explicit concatentation
$_ = 'bar';
$_ = 'Foo' . $_;
say;
# lvalue substr
$_ = 'bar';
substr $_, 0, 0, 'Foo';
say;
# interpolation as concatenation
# (NOT safe if concatenate sigils)
$_ = 'bar';
$_ = "Foo$_";
say;

View file

@ -0,0 +1,4 @@
-->
<span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"World"</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"Hello "</span><span style="color: #0000FF;">&</span><span style="color: #000000;">s</span>
<!--

View file

@ -0,0 +1,6 @@
/# Rosetta Code problem: https://rosettacode.org/wiki/String_prepend
by Galileo, 10/2022 #/
"Hello " var s
s "world" chain var s
s print

View file

@ -0,0 +1,19 @@
go =>
S = "123456789",
println(S),
S := "A" ++ S,
println(S),
% append
append("B",S,T),
S := T,
println(S),
% insert at position
S := insert(S,1,'C'), % note: must be a char to keep it a proper string
println(S),
% insert many characters
S := insert_all(S,1,"DE"),
println(S),
nl.

View file

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

Some files were not shown because too many files have changed in this diff Show more