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,7 @@
---
category:
- String manipulation
- Simple
- Strings
from: http://rosettacode.org/wiki/String_interpolation_(included)
note: Basic language learning

View file

@ -0,0 +1,21 @@
{{basic data operation}}
{{omit from|NSIS}}
{{omit from|BBC BASIC}}
Given a string and defined variables or values, [[wp:String literal#Variable_interpolation|string interpolation]] is the replacement of defined character sequences in the string by values or variable values.
: For example, given an original string of <code>"Mary had a X lamb."</code>, a value of "big", and if the language replaces X in its interpolation routine, then the result of its interpolation would be the string <code>"Mary had a big lamb"</code>.
:(Languages usually include an infrequently used character or sequence of characters to indicate what is to be replaced such as "%", or "#" rather than "X").
;Task:
# Use your languages inbuilt string interpolation abilities to interpolate a string missing the text <code>"little"</code> which is held in a variable, to produce the output string <code>"Mary had a little lamb"</code>.
# If possible, give links to further documentation on your languages string interpolation features.
<small>Note: The task is not to create a string interpolation routine, but to show a language's built-in capability.</small>
{{Template:Strings}}
<br><br>

View file

@ -0,0 +1,4 @@
V extra = little
print(Mary had a extra lamb.)
print(Mary had a #. lamb..format(extra))
print(f:Mary had a {extra} lamb.)

View file

@ -0,0 +1,255 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program insertString64.s */
/* In assembler, there is no function to insert a chain */
/* so this program offers two functions to insert */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ CHARPOS, '@'
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szString: .asciz " string "
szString1: .asciz "insert"
szString2: .asciz "abcd@efg"
szString3: .asciz "abcdef @"
szString4: .asciz "@ abcdef"
szCarriageReturn: .asciz "\n"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: // entry of program
ldr x0,qAdrszString // string address
ldr x1,qAdrszString1 // string address
mov x2,#0
bl strInsert //
// return new pointer
bl affichageMess // display result string
ldr x0,qAdrszCarriageReturn
bl affichageMess
ldr x0,qAdrszString // string address
ldr x1,qAdrszString1 // string address
mov x2,#3
bl strInsert //
// return new pointer
bl affichageMess // display result string
ldr x0,qAdrszCarriageReturn
bl affichageMess
ldr x0,qAdrszString // string address
ldr x1,qAdrszString1 // string address
mov x2,#40
bl strInsert //
// return new pointer
bl affichageMess // display result string
ldr x0,qAdrszCarriageReturn
bl affichageMess
ldr x0,qAdrszString2 // string address
ldr x1,qAdrszString1 // string address
bl strInsertAtChar //
// return new pointer
bl affichageMess // display result string
ldr x0,qAdrszCarriageReturn
bl affichageMess
ldr x0,qAdrszString3 // string address
ldr x1,qAdrszString1 // string address
bl strInsertAtChar //
// return new pointer
bl affichageMess // display result string
ldr x0,qAdrszCarriageReturn
bl affichageMess
ldr x0,qAdrszString4 // string address
ldr x1,qAdrszString1 // string address
bl strInsertAtChar //
// return new pointer
bl affichageMess // display result string
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 the system call
qAdrszString: .quad szString
qAdrszString1: .quad szString1
qAdrszString2: .quad szString2
qAdrszString3: .quad szString3
qAdrszString4: .quad szString4
qAdrszCarriageReturn: .quad szCarriageReturn
/******************************************************************/
/* insertion of a sub-chain in a chain in the desired position */
/******************************************************************/
/* x0 contains the address of string 1 */
/* x1 contains the address of string to insert */
/* x2 contains the position of insertion :
0 start string
if x2 > lenght string 1 insert at end of string*/
/* x0 return the address of new string on the heap */
strInsert:
stp x1,lr,[sp,-16]! // save registers
stp x2,x3,[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 x8,#0 // index load characters string 1
cmp x2,#0 // index insertion = 0
beq 5f // insertion at string 1 begin
3: // loop copy characters string 1
ldrb w0,[x6,x8] // load character
cmp w0,#0 // end string ?
beq 5f // insertion at end
strb w0,[x5,x8] // store character in output string
add x8,x8,#1 // increment index
cmp x8,x2 // < insertion index ?
blt 3b // yes -> loop
5:
mov x4,x8 // init index character output string
mov x3,#0 // index load characters insertion string
6:
ldrb w0,[x1,x3] // load characters insertion string
cmp w0,#0 // end string ?
beq 7f
strb w0,[x5,x4] // store in output string
add x3,x3,#1 // increment index
add x4,x4,#1 // increment output index
b 6b // and loop
7:
ldrb w0,[x6,x8] // load other character string 1
strb w0,[x5,x4] // store in output string
cmp x0,#0 // end string 1 ?
beq 8f // yes -> end
add x4,x4,#1 // increment output index
add x8,x8,#1 // increment index
b 7b // and loop
8:
mov x0,x5 // return output string address
b 100f
99: // error
mov x0,#-1
100:
ldp x2,x3,[sp],16 // restaur 2 registers
ldp x1,lr,[sp],16 // restaur 2 registers
ret
/******************************************************************/
/* insert string at character insertion */
/******************************************************************/
/* x0 contains the address of string 1 */
/* x1 contains the address of insertion string */
/* x0 return the address of new string on the heap */
/* or -1 if error */
strInsertAtChar:
stp x1,lr,[sp,-16]! // save registers
stp x2,x3,[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 to insertion string
ldrb w4,[x1,x5]
cmp x4,#0
cinc x5,x5,ne // increment to one if not equal
bne 2b // and loop
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 x2,0
mov x4,0
3: // loop copy string begin
ldrb w3,[x6,x2]
cmp w3,0
beq 99f
cmp w3,CHARPOS // insertion character ?
beq 5f // yes
strb w3,[x5,x4] // no store character in output string
add x2,x2,1
add x4,x4,1
b 3b // and loop
5: // x4 contains position insertion
add x8,x4,1 // init index character output string
// at position insertion + one
mov x3,#0 // index load characters insertion string
6:
ldrb w0,[x1,x3] // load characters insertion string
cmp w0,#0 // end string ?
beq 7f // yes
strb w0,[x5,x4] // store in output string
add x3,x3,#1 // increment index
add x4,x4,#1 // increment output index
b 6b // and loop
7: // loop copy end string
ldrb w0,[x6,x8] // load other character string 1
strb w0,[x5,x4] // store in output string
cmp x0,#0 // end string 1 ?
beq 8f // yes -> end
add x4,x4,#1 // increment output index
add x8,x8,#1 // increment index
b 7b // and loop
8:
mov x0,x5 // return output string address
b 100f
99: // error
mov x0,#-1
100:
ldp x2,x3,[sp],16 // restaur 2 registers
ldp x1,lr,[sp],16 // restaur 2 registers
ret
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -0,0 +1,12 @@
main:(
# as a STRING #
STRING extra = "little";
printf(($"Mary had a "g" lamb."l$, extra));
# as a FORMAT #
FORMAT extraf = $"little"$;
printf($"Mary had a "f(extraf)" lamb."l$);
# or: use simply use STRING concatenation #
print(("Mary had a "+extra+" lamb.", new line))
)

View file

@ -0,0 +1,19 @@
s 'Mary had a ∆ lamb' s[s'∆'] 'little' s s
s
Mary had a little lamb
⍝⍝⍝ Or, for a more general version which interpolates multiple positional arguments and can
⍝⍝⍝ handle both string and numeric types...
r s sInterp sv
⍝⍝ Interpolate items in sv into s (string field substitution)
⍝ s: string - format string, '∆' used for interpolation points
⍝ sv: vector - vector of items to interpolate into s
⍝ r: interpolated string
s[('∆'=s)/s] ¨(¨sv)
r s
'Mary had a ∆ lamb, its fleece was ∆ as ∆.' sInterp 'little' 'black' 'night'
Mary had a little lamb, its fleece was black as night.
'Mary had a ∆ lamb, its fleece was ∆ as ∆.' sInterp 'little' 'large' 42
Mary had a little lamb, its fleece was large as 42.

View file

@ -0,0 +1,253 @@
/* ARM assembly Raspberry PI */
/* program insertString.s */
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/*******************************************/
/* Constantes */
/*******************************************/
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
.equ BRK, 0x2d @ Linux syscall
.equ CHARPOS, '@'
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szString: .asciz " string "
szString1: .asciz "insert"
szString2: .asciz "abcd@efg"
szString3: .asciz "abcdef @"
szString4: .asciz "@ abcdef"
szCarriageReturn: .asciz "\n"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main: // entry of program
ldr r0,iAdrszString // string address
ldr r1,iAdrszString1 // string address
mov r2,#0
bl strInsert //
// return new pointer
bl affichageMess // display result string
ldr r0,iAdrszCarriageReturn
bl affichageMess
ldr r0,iAdrszString // string address
ldr r1,iAdrszString1 // string address
mov r2,#3
bl strInsert //
// return new pointer
bl affichageMess // display result string
ldr r0,iAdrszCarriageReturn
bl affichageMess
ldr r0,iAdrszString // string address
ldr r1,iAdrszString1 // string address
mov r2,#40
bl strInsert //
// return new pointer
bl affichageMess // display result string
ldr r0,iAdrszCarriageReturn
bl affichageMess
ldr r0,iAdrszString2 // string address
ldr r1,iAdrszString1 // string address
bl strInsertAtChar //
// return new pointer
bl affichageMess // display result string
ldr r0,iAdrszCarriageReturn
bl affichageMess
ldr r0,iAdrszString3 // string address
ldr r1,iAdrszString1 // string address
bl strInsertAtChar //
// return new pointer
bl affichageMess // display result string
ldr r0,iAdrszCarriageReturn
bl affichageMess
ldr r0,iAdrszString4 // string address
ldr r1,iAdrszString1 // string address
bl strInsertAtChar //
// return new pointer
bl affichageMess // display result string
ldr r0,iAdrszCarriageReturn
bl affichageMess
100: // standard end of the program
mov r0, #0 // return code
mov r7, #EXIT // request to exit program
svc 0 // perform the system call
iAdrszString: .int szString
iAdrszString1: .int szString1
iAdrszString2: .int szString2
iAdrszString3: .int szString3
iAdrszString4: .int szString4
iAdrszCarriageReturn: .int szCarriageReturn
/******************************************************************/
/* insertion of a sub-chain in a chain in the desired position */
/******************************************************************/
/* r0 contains the address of string 1 */
/* r1 contains the address of string to insert */
/* r2 contains the position of insertion :
0 start string
if r2 > lenght string 1 insert at end of string*/
/* r0 return the address of new string on the heap */
strInsert:
push {r1-r4,lr} @ save registres
mov r3,#0 // length counter
1: // compute length of string 1
ldrb r4,[r0,r3]
cmp r4,#0
addne r3,r3,#1 // increment to one if not equal
bne 1b // loop if not equal
mov r5,#0 // length counter insertion string
2: // compute length of insertion string
ldrb r4,[r1,r5]
cmp r4,#0
addne r5,r5,#1 // increment to one if not equal
bne 2b
cmp r5,#0
beq 99f // string empty -> error
add r3,r3,r5 // add 2 length
add r3,r3,#1 // +1 for final zero
mov r6,r0 // save address string 1
mov r0,#0 // allocation place heap
mov r7,#BRK // call system 'brk'
svc #0
mov r5,r0 // save address heap for output string
add r0,r0,r3 // reservation place r3 length
mov r7,#BRK // call system 'brk'
svc #0
cmp r0,#-1 // allocation error
beq 99f
//
mov r7,#0 // index load characters string 1
cmp r2,#0 // index insertion = 0
beq 5f // insertion at string 1 begin
3: // loop copy characters string 1
ldrb r0,[r6,r7] // load character
cmp r0,#0 // end string ?
beq 5f // insertion at end
strb r0,[r5,r7] // store character in output string
add r7,r7,#1 // increment index
cmp r7,r2 // < insertion index ?
blt 3b // yes -> loop
5:
mov r4,r7 // init index character output string
mov r3,#0 // index load characters insertion string
6:
ldrb r0,[r1,r3] // load characters insertion string
cmp r0,#0 // end string ?
beq 7f
strb r0,[r5,r4] // store in output string
add r3,r3,#1 // increment index
add r4,r4,#1 // increment output index
b 6b // and loop
7:
ldrb r0,[r6,r7] // load other character string 1
strb r0,[r5,r4] // store in output string
cmp r0,#0 // end string 1 ?
beq 8f // yes -> end
add r4,r4,#1 // increment output index
add r7,r7,#1 // increment index
b 7b // and loop
8:
mov r0,r5 // return output string address
b 100f
99: // error
mov r0,#-1
100:
pop {r1-r4,lr} @ restaur registers
bx lr @ return
/******************************************************************/
/* insert string at character insertion */
/******************************************************************/
/* r0 contains the address of string 1 */
/* r1 contains the address of insertion string */
/* r0 return the address of new string on the heap */
/* or -1 if error */
strInsertAtChar:
push {r1-r7,lr} @ save registres
mov r3,#0 // length counter
1: // compute length of string 1
ldrb r4,[r0,r3]
cmp r4,#0
addne r3,r3,#1 // increment to one if not equal
bne 1b // loop if not equal
mov r5,#0 // length counter insertion string
2: // compute length to insertion string
ldrb r4,[r1,r5]
cmp r4,#0
addne r5,r5,#1 // increment to one if not equal
bne 2b // and loop
cmp r5,#0
beq 99f // string empty -> error
add r3,r3,r5 // add 2 length
add r3,r3,#1 // +1 for final zero
mov r6,r0 // save address string 1
mov r0,#0 // allocation place heap
mov r7,#BRK // call system 'brk'
svc #0
mov r5,r0 // save address heap for output string
add r0,r0,r3 // reservation place r3 length
mov r7,#BRK // call system 'brk'
svc #0
cmp r0,#-1 // allocation error
beq 99f
mov r2,#0
mov r4,#0
3: // loop copy string begin
ldrb r3,[r6,r2]
cmp r3,#0
beq 99f
cmp r3,#CHARPOS // insertion character ?
beq 5f // yes
strb r3,[r5,r4] // no store character in output string
add r2,r2,#1
add r4,r4,#1
b 3b // and loop
5: // r4 contains position insertion
add r7,r4,#1 // init index character output string
// at position insertion + one
mov r3,#0 // index load characters insertion string
6:
ldrb r0,[r1,r3] // load characters insertion string
cmp r0,#0 // end string ?
beq 7f // yes
strb r0,[r5,r4] // store in output string
add r3,r3,#1 // increment index
add r4,r4,#1 // increment output index
b 6b // and loop
7: // loop copy end string
ldrb r0,[r6,r7] // load other character string 1
strb r0,[r5,r4] // store in output string
cmp r0,#0 // end string 1 ?
beq 8f // yes -> end
add r4,r4,#1 // increment output index
add r7,r7,#1 // increment index
b 7b // and loop
8:
mov r0,r5 // return output string address
b 100f
99: // error
mov r0,#-1
100:
pop {r1-r7,lr} @ restaur registers
bx lr @ return
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"

View file

@ -0,0 +1,6 @@
#!/usr/bin/awk -f
BEGIN {
str="Mary had a # lamb."
gsub(/#/, "little", str)
print str
}

View file

@ -0,0 +1,5 @@
PROC Main()
CHAR ARRAY extra="little"
PrintF("Mary had a %S lamb.%E",extra)
RETURN

View file

@ -0,0 +1,11 @@
with Ada.Strings.Fixed, Ada.Text_IO;
use Ada.Strings, Ada.Text_IO;
procedure String_Replace is
Original : constant String := "Mary had a @__@ lamb.";
Tbr : constant String := "@__@";
New_Str : constant String := "little";
Index : Natural := Fixed.Index (Original, Tbr);
begin
Put_Line (Fixed.Replace_Slice (
Original, Index, Index + Tbr'Length - 1, New_Str));
end String_Replace;

View file

@ -0,0 +1 @@
Put_Line ("Mary had a " & New_Str & " lamb.");

View file

@ -0,0 +1,5 @@
const little = "little"
printf ("Mary had a %s lamb\n", little)
// alternatively
println ("Mary had a " + little + " lamb")

View file

@ -0,0 +1,3 @@
sizeOfLamb: "little"
print ~"Mary had a |sizeOfLamb| lamb."

View file

@ -0,0 +1,4 @@
string s1 = "big";
write("Mary had a " + s1 + " lamb");
s1 = "little";
write("Mary also had a ", s1, "lamb");

View file

@ -0,0 +1,9 @@
; Using the = operator
LIT = little
string = Mary had a %LIT% lamb.
; Using the := operator
LIT := "little"
string := "Mary had a" LIT " lamb."
MsgBox %string%

View file

@ -0,0 +1,5 @@
x$ = "big"
print "Mary had a "; x$; " lamb"
x$ = "little"
print "Mary also had a "; ljust(x$, length(x$)); " lamb"

View file

@ -0,0 +1,4 @@
Str (3•Type)2=•Type,0,1,0
_interpolate {(•Fmt(¬Str)¨𝕨)((𝕗=𝕩)/)𝕩}
'a'"def"451,2,30.34241 '·'_interpolate "Hi · am · and · or · float ·"

View file

@ -0,0 +1,11 @@
@echo off
setlocal enabledelayedexpansion
call :interpolate %1 %2 res
echo %res%
goto :eof
:interpolate
set pat=%~1
set str=%~2
set %3=!pat:X=%str%!
goto :eof

View file

@ -0,0 +1,2 @@
>interpolate.cmd "Mary had a X lamb" little
Mary had a little lamb

View file

@ -0,0 +1 @@
@("Mary had a X lamb":?a X ?z) & str$(!a little !z)

View file

@ -0,0 +1,11 @@
#include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}

View file

@ -0,0 +1,44 @@
// Variable argument template
#include <string>
#include <vector>
using std::string;
using std::vector;
template<typename S, typename... Args>
string interpolate( const S& orig , const Args&... args)
{
string out(orig);
// populate vector from argument list
auto va = {args...};
vector<string> v{va};
size_t i = 1;
for( string s: v)
{
string is = std::to_string(i);
string t = "{" + is + "}"; // "{1}", "{2}", ...
try
{
auto pos = out.find(t);
if ( pos != out.npos) // found token
{
out.erase(pos, t.length()); //erase token
out.insert( pos, s); // insert arg
}
i++; // next
}
catch( std::exception& e)
{
std::cerr << e.what() << std::endl;
}
} // for
return out;
}

View file

@ -0,0 +1,4 @@
set extra='little'
echo Mary had a $extra lamb.
echo "Mary had a $extra lamb."
printf "Mary had a %s lamb.\n" $extra

View file

@ -0,0 +1,9 @@
class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}

View file

@ -0,0 +1,7 @@
#include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}

View file

@ -0,0 +1,12 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. interpolation-included.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 extra PIC X(6) VALUE "little".
PROCEDURE DIVISION.
DISPLAY FUNCTION SUBSTITUTE("Mary had a X lamb.", "X", extra)
GOBACK
.

View file

@ -0,0 +1,2 @@
(let [little "little"]
(println (format "Mary had a %s lamb." little)))

View file

@ -0,0 +1,2 @@
size = 'little'
console.log "Mary had a #size lamb."

View file

@ -0,0 +1,9 @@
size = 'little'
console.log "Mary had a #{size} lamb." # Mary had a little lamb.
console.log "Escaping: \#{}" # Escaping: #{}
console.log 'No #{ interpolation} with single quotes' # No #{ interpolation} with single quotes
# Multi-line strings and arbtrary expressions work: 20
console.log """
Multi-line strings and arbtrary expressions work: #{ 5 * 4 }
"""

View file

@ -0,0 +1,2 @@
(let ((extra "little"))
(format t "Mary had a ~A lamb.~%" extra))

View file

@ -0,0 +1,6 @@
void main() {
import std.stdio, std.string;
"Mary had a %s lamb.".format("little").writeln;
"Mary had a %2$s %1$s lamb.".format("little", "white").writeln;
}

View file

@ -0,0 +1 @@
PrintLn(Format('Mary had a %s lamb.', ['little']))

View file

@ -0,0 +1,36 @@
program Project1;
uses
System.SysUtils;
var
Template : string;
Marker : string;
Description : string;
Value : integer;
Output : string;
begin
// StringReplace can be used if you are definitely using strings
// http://docwiki.embarcadero.com/Libraries/XE7/en/System.SysUtils.StringReplace
Template := 'Mary had a X lamb.';
Marker := 'X';
Description := 'little';
Output := StringReplace(Template, Marker, Description, [rfReplaceAll, rfIgnoreCase]);
writeln(Output);
// You could also use format to do the same thing.
// http://docwiki.embarcadero.com/Libraries/XE7/en/System.SysUtils.Format
Template := 'Mary had a %s lamb.';
Description := 'little';
Output := format(Template,[Description]);
writeln(Output);
// Unlike StringReplace, format is not restricted to strings.
Template := 'Mary had a %s lamb. It was worth $%d.';
Description := 'little';
Value := 20;
Output := format(Template,[Description, Value]);
writeln(Output);
end.

View file

@ -0,0 +1,2 @@
let lamb_size = "little"
print("Mary had a \(lamb_size) lamb.")

View file

@ -0,0 +1,2 @@
def adjective := "little"
`Mary had a $adjective lamb`

View file

@ -0,0 +1,2 @@
def adjective := "little"
simple__quasiParser.valueMaker("Mary had a ${0} lamb").substitute([adjective])

View file

@ -0,0 +1,2 @@
IMPORT STD;
STD.Str.FindReplace('Mary had a X Lamb', 'X','little');

View file

@ -0,0 +1,5 @@
;; format uses %a or ~a as replacement directive
(format "Mary had a ~a lamb" "little")
→ "Mary had a little lamb"
(format "Mary had a %a lamb" "little")
→ "Mary had a little lamb"

View file

@ -0,0 +1,7 @@
import extensions;
public program()
{
var s := "little";
console.printLineFormatted("Mary had a {0} lamb.",s).readChar()
}

View file

@ -0,0 +1,2 @@
x = "little"
IO.puts "Mary had a #{x} lamb"

View file

@ -0,0 +1,4 @@
(let ((little "little"))
(format "Mary had a %s lamb." little)
;; message takes a format string as argument
(message "Mary had a %s lamb." little))

View file

@ -0,0 +1,4 @@
constant lambType = "little"
sequence s
s = sprintf("Mary had a %s lamb.",{lambType})
puts(1,s)

View file

@ -0,0 +1,2 @@
let lambType = "little"
printfn "Mary had a %s lamb." lambType

View file

@ -0,0 +1,7 @@
USE: formatting
SYMBOL: little
"little" little set
little get "Mary had a %s lamb" sprintf

View file

@ -0,0 +1,5 @@
USE: formatting
CONSTANT: little "little"
little "Mary had a %s lamb" sprintf

View file

@ -0,0 +1,8 @@
/* created by Aykayayciti Earl Lamont Montgomery
April 9th, 2018 */
size = "little"
> @ "Mary had a $size lamb"
// line 1: use of the = operator
// line 2: use of the @ and $ operator

View file

@ -0,0 +1,4 @@
fansh> x := "little"
little
fansh> echo ("Mary had a $x lamb")
Mary had a little lamb

View file

@ -0,0 +1,26 @@
variable 'src
variable #src
variable 'out
variable #out
: Replace~ dup [char] ~ = \ test for escape char
if 'out @ 1+ #out @ type drop \ replace the escape char
else emit \ otherwise write char
then ;
: format 0
begin dup #src @ u<
while 1+ dup 'src @ + c@
replace~
repeat ;
\ Test of function
Here 'src ! ," Mary had a ~ lamb" here 'src @ - #src !
page
cr ." Original : "
'src @ 1+ #src @ type
cr ." 1st Replacement : "
here 'out ! ," little" here 'out @ - #out !
format
cr ." 2nd Replacement : "
here 'out ! ," BIG" here 'out @ - #out !
format

View file

@ -0,0 +1,19 @@
program interpolate
write (*,*) trim(inter("Mary had a X lamb.","X","little"))
contains
elemental function inter(string,place,ins) result(new)
character(len=*), intent(in) :: string,place,ins
character(len=len(string)+max(0,len(ins)-len(place))) :: new
integer :: idx
idx = index(string,place)
if ( idx == 0 ) then
new = string
else
new = string(1:idx-1)//ins//string(idx+len(place):len(string))
end if
end function inter
end program interpolate

View file

@ -0,0 +1,9 @@
' FB 1.05.0 Win64
#Include "crt/stdio.bi" '' header needed for printf
Dim x As String = "big"
Print "Mary had a "; x; " lamb" '' FB's native Print statement
x = "little"
printf("Mary also had a %s lamb", x)
Sleep

View file

@ -0,0 +1,2 @@
x = "little"
println["Mary had a $x lamb."]

View file

@ -0,0 +1,2 @@
X = 'little'
println( "Mary had a $X lamb." )

View file

@ -0,0 +1,7 @@
CFStringRef string, extra
extra = @"little"
string = fn StringWithFormat( @"Mary had a %@ lamb", extra )
print string
HandleEvents

View file

@ -0,0 +1,5 @@
Public Sub Main()
Print Subst("Mary had a &1 lamb", "little")
End

View file

@ -0,0 +1,6 @@
#listix#
<how> //little
<what> //has a @<how> lamb
<main> //Mary @<what>

View file

@ -0,0 +1,12 @@
package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}

View file

@ -0,0 +1,2 @@
def adj = 'little'
assert 'Mary had a little lamb.' == "Mary had a ${adj} lamb."

View file

@ -0,0 +1,3 @@
import Text.Printf
main = printf "Mary had a %s lamb\n" "little"

View file

@ -0,0 +1,7 @@
class Program {
static function main() {
var extra = 'little';
var formatted = 'Mary had a $extra lamb.';
Sys.println(formatted);
}
}

View file

@ -0,0 +1,4 @@
CHARACTER original="Mary had a X lamb", little = "little", output_string*100
output_string = original
EDIT(Text=output_string, Right='X', RePLaceby=little)

View file

@ -0,0 +1,5 @@
s2 := "humongous"
s3 := "little"
s1 := "Mary had a humongous lamb."
s1 ?:= tab(find(s2)) || (=s2,s3) || tab(0) # replaces the first instance of s2 with s3
while s1 ?:= tab(find(s2)) || (=s2,s3) || tab(0) # replaces all instances of s2 with s3, equivalent to replace

View file

@ -0,0 +1,9 @@
require 'printf'
'Mary had a %s lamb.' sprintf <'little'
Mary had a little lamb.
require 'strings'
('%s';'little') stringreplace 'Mary had a %s lamb.'
Mary had a little lamb.
'Mary had a %s lamb.' rplc '%s';'little'
Mary had a little lamb.

View file

@ -0,0 +1 @@
open'strings printf'

View file

@ -0,0 +1,2 @@
String adjective = "little";
String lyric = String.format("Mary had a %s lamb", adjective);

View file

@ -0,0 +1,2 @@
String adjective = "little";
String lyric = "Mary had a %s lamb".formatted(adjective);

View file

@ -0,0 +1,2 @@
String adjective = "little";
System.out.printf("Mary had a %s lamb", adjective);

View file

@ -0,0 +1,5 @@
StringBuilder string = new StringBuilder();
Formatter formatter = new Formatter(string);
String adjective = "little";
formatter.format("Mary had a %s lamb", adjective);
formatter.flush();

View file

@ -0,0 +1,9 @@
String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little); //does not change the original String
System.out.println(replaced);
//Alternative:
System.out.printf("Mary had a %s lamb.", little);
//Alternative:
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);

View file

@ -0,0 +1,3 @@
var original = "Mary had a X lamb";
var little = "little";
var replaced = original.replace("X", little); //does not change the original string

View file

@ -0,0 +1,3 @@
// ECMAScript 6
var X = "little";
var replaced = `Mary had a ${X} lamb`;

View file

@ -0,0 +1,2 @@
"little" as $x
| "Mary had a \($x) lamb"

View file

@ -0,0 +1,2 @@
$ jq -M -n -r '"Jürgen" as $x | "The string \"\($x)\" has \($x|length) codepoints."'
The string "Jürgen" has 6 codepoints.

View file

@ -0,0 +1,2 @@
X = "little"
"Mary had a $X lamb"

View file

@ -0,0 +1,14 @@
// version 1.0.6
fun main(args: Array<String>) {
val s = "little"
// String interpolation using a simple variable
println("Mary had a $s lamb")
// String interpolation using an expression (need to wrap it in braces)
println("Mary had a ${s.toUpperCase()} lamb")
// However if a simple variable is immediately followed by a letter, digit or underscore
// it must be treated as an expression
println("Mary had a ${s}r lamb") // not $sr
}

View file

@ -0,0 +1,6 @@
{def original Mary had a X lamb}
-> original
{def Y little}
-> Y
{S.replace X by {Y} in {original}}
-> Mary had a little lamb

View file

@ -0,0 +1 @@
email_merge("Mary had a #adjective# lamb", map("token"="little", "adjective"=""), null, 'plain')

View file

@ -0,0 +1,4 @@
local str="little"
put merge("Mary had a [[str]] lamb.")
-- Mary had a little lamb.

View file

@ -0,0 +1,2 @@
str = string.gsub( "Mary had a X lamb.", "X", "little" )
print( str )

View file

@ -0,0 +1,3 @@
str1 = string.format( "Mary had a %s lamb.", "little" )
str2 = ( "Mary had a %s lamb." ):format( "little" )
print( str1, str2 )

View file

@ -0,0 +1 @@
print "Mary had a \n lamb" -- The \n is interpreted as an escape sequence for a newline

View file

@ -0,0 +1,13 @@
module checkit {
size$="little"
m$=format$("Mary had a {0} lamb.", size$)
Print m$
Const RightJustify=1
\\ format$(string_expression) process escape codes
Report RightJustify, format$(format$("Mary had a {0} {1} lamb.\r\n We use {0} for size, and {1} for color\r\n", size$, "wh"+"ite"))
\\ we can use { } for multi line string
Report RightJustify, format$({Mary had a {0} {1} lamb.
We use {0} for size, and {1} for color
}, size$, "wh"+"ite")
}
checkit

View file

@ -0,0 +1,3 @@
Extra = "little";
StringReplace["Mary had a X lamb.", {"X" -> Extra}]
->"Mary had a little lamb."

View file

@ -0,0 +1 @@
printf(true, "Mary had a ~a lamb", "little");

View file

@ -0,0 +1,9 @@
/**
<doc><h2>String interpolation, in Neko</h2>
<p><a href="https://nekovm.org/doc/view/string/">NekoVM String Library</a></p>
</doc>
**/
var sprintf = $loader.loadprim("std@sprintf", 2)
$print(sprintf("Mary had a %s lamb\n", "little"))

View file

@ -0,0 +1,14 @@
using System;
using System.Console;
using Nemerle.IO; // contains printf() and print()
module Stringy
{
Main() : void
{
def extra = "little";
printf("Mary had a %s lamb.\n", extra);
print("Mary had a $extra lamb.\n");
WriteLine($"Mary had a $extra lamb.");
}
}

View file

@ -0,0 +1,35 @@
/* NetRexx */
options replace format comments java crossref savelog symbols
import java.text.MessageFormat
import java.text.FieldPosition
useBif()
useMessageFormat()
return
method useBif public static
st = "Mary had a %1$ lamb."
si = 'little'
say st.changestr('%1$', si)
return
method useMessageFormat public static
result = StringBuffer('')
args = Object [ -
Object Integer(7), -
Object Date(), -
Object 'a disturbance in the Force' -
]
msgfmt = MessageFormat('At {1, time} on {1, date}, there was {2} on planet {0, number, integer}.')
result = msgfmt.format(args, result, FieldPosition(0))
say result
return

View file

@ -0,0 +1,6 @@
import strutils
var str = "little"
echo "Mary had a $# lamb".format(str)
echo "Mary had a $# lamb" % [str]
# Note: doesn't need an array for a single substitution, but uses an array for multiple substitutions.

View file

@ -0,0 +1,5 @@
import strformat
var str: string = "little"
echo fmt"Mary had a {str} lamb"
echo &"Mary had a {str} lamb"

View file

@ -0,0 +1,2 @@
let extra = "little" in
Printf.printf "Mary had a %s lamb." extra

View file

@ -0,0 +1,2 @@
let extra = "little" in
[%string "Mary had a $extra lamb."]

View file

@ -0,0 +1,4 @@
main: func {
X := "little"
"Mary had a #{X} lamb" println()
}

View file

@ -0,0 +1,4 @@
declare
X = "little"
in
{System.showInfo "Mary had a "#X#" lamb"}

View file

@ -0,0 +1,6 @@
GEN
string_interpolate(GEN n)
{
pari_printf("The value was: %Ps.\n", n);
GEN s = pari_sprintf("Storing %Ps in a string", n);
}

View file

@ -0,0 +1,2 @@
s=Strprintf("The value was: %Ps", 1<<20);
printf("The value was: %Ps", 1<<20);

View file

@ -0,0 +1,5 @@
<?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>

View file

@ -0,0 +1,32 @@
*process or(!) source xref attributes;
sit: Proc Options(main);
/*********************************************************************
* Test string replacement
* 02.08.2013 Walter Pachl
*********************************************************************/
Dcl s Char(50) Var Init('Mary had a &X lamb. It is &X');
Put Edit(repl(s,'little','&X'))(Skip,A);
repl: Proc(str,new,old) Returns(Char(50) Var);
/*********************************************************************
* ooREXX has CHANGESTR(old,str,new[,count])
* repl follows, however, the translate "philosophy"
* translate(str,new,old) when old and new are just a character each
* and replaces all occurrences of old in str by new
*********************************************************************/
Dcl str Char(*) Var;
Dcl (new,old) Char(*);
Dcl (res,tmp) Char(50) Var init('');
Dcl p Bin Fixed(31);
tmp=str; /* copy the input string */
Do Until(p=0);
p=index(tmp,old); /* position of old in tmp */
If p>0 Then Do; /* found */
res=res!!left(tmp,p-1)!!new; /* append new to current result*/
tmp=substr(tmp,p+length(old)); /* prepare rest of input */
End;
End;
res=res!!tmp; /* final append */
Return(res);
End;
End;

View file

@ -0,0 +1,3 @@
$extra = "little";
print "Mary had a $extra lamb.\n";
printf "Mary had a %s lamb.\n", $extra;

View file

@ -0,0 +1,5 @@
(phixonline)-->
<span style="color: #004080;">string</span> <span style="color: #000000;">size</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"little"</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Mary had a %s lamb."</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">size</span><span style="color: #0000FF;">})</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">s</span>
<!--

View file

@ -0,0 +1,12 @@
/# Rosetta Code problem: https://rosettacode.org/wiki/String_interpolation_(included)
by Galileo, 11/2022 #/
include ..\Utilitys.pmt
"big" var s
( "Mary had a " s " lamb" ) lprint nl
"little" var s
( "Mary had a " s " lamb" ) lprint

View file

@ -0,0 +1,7 @@
main =>
V = "little",
printf("Mary had a %w lamb\n", V),
% As a function
S = to_fstring("Mary had a %w lamb", V),
println(S).

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