Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1 @@
type String is array (Positive range <>) of Character;

View file

@ -0,0 +1 @@
A (<first-index>..<last-index>)

View file

@ -0,0 +1,14 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
procedure Test_Slices is
Str : constant String := "abcdefgh";
N : constant := 2;
M : constant := 3;
begin
Put_Line (Str (Str'First + N - 1..Str'First + N + M - 2));
Put_Line (Str (Str'First + N - 1..Str'Last));
Put_Line (Str (Str'First..Str'Last - 1));
Put_Line (Head (Tail (Str, Str'Last - Index (Str, "d", 1)), M));
Put_Line (Head (Tail (Str, Str'Last - Index (Str, "de", 1) - 1), M));
end Test_Slices;

View file

@ -0,0 +1,56 @@
identification division.
program-id. substring.
environment division.
configuration section.
repository.
function all intrinsic.
data division.
working-storage section.
01 original.
05 value "this is a string".
01 starting pic 99 value 3.
01 width pic 99 value 8.
01 pos pic 99.
01 ender pic 99.
01 looking pic 99.
01 indicator pic x.
88 found value high-value when set to false is low-value.
01 look-for pic x(8).
procedure division.
substring-main.
display "Original |" original "|, n = " starting " m = " width
display original(starting : width)
display original(starting :)
display original(1 : length(original) - 1)
move "a" to look-for
move 1 to looking
perform find-position
if found
display original(pos : width)
end-if
move "is a st" to look-for
move length(trim(look-for)) to looking
perform find-position
if found
display original(pos : width)
end-if
goback.
find-position.
set found to false
compute ender = length(original) - looking
perform varying pos from 1 by 1 until pos > ender
if original(pos : looking) equal look-for then
set found to true
exit perform
end-if
end-perform
.
end program substring.

View file

@ -0,0 +1,39 @@
sequence baseString, subString, findString
integer findChar
integer m, n
baseString = "abcdefghijklmnopqrstuvwxyz"
-- starting from n characters in and of m length;
n = 12
m = 5
subString = baseString[n..n+m-1]
puts(1, subString )
puts(1,'\n')
-- starting from n characters in, up to the end of the string;
n = 12
subString = baseString[n..$]
puts(1, subString )
puts(1,'\n')
-- whole string minus last character;
subString = baseString[1..$-1]
puts(1, subString )
puts(1,'\n')
-- starting from a known character within the string and of m length;
findChar = 'o'
m = 5
n = find(findChar,baseString)
subString = baseString[n..n+m-1]
puts(1, subString )
puts(1,'\n')
-- starting from a known substring within the string and of m length.
findString = "pq"
m = 5
n = match(findString,baseString)
subString = baseString[n..n+m-1]
puts(1, subString )
puts(1,'\n')

View file

@ -0,0 +1,14 @@
string = "Microsoft Small Basic"
n = 3
m = 7
' starting from n haracters in and of m length
TextWindow.WriteLine(Text.GetSubText(string, n, m))
' starting from n characters in, up to the end of the string
TextWindow.WriteLine(Text.GetSubTextToEnd(string, n))
' whole string minus the last character
TextWindow.WriteLine(Text.GetSubText(string, 1, Text.GetLength(string) - 1))
' starting from a known character within the string and of m length
TextWindow.WriteLine(Text.GetSubText(string, Text.GetIndexOf(string, "a"), m))
' starting from a known substring within the string and of m length
TextWindow.WriteLine(Text.GetSubText(string, Text.GetIndexOf(string, "Small"), m))

View file

@ -0,0 +1,26 @@
REM https://github.com/Eva-Broccoli/OPL-Rosetta-Code/blob/main/Substrng.opl
PROC main:
LOCAL string$(68),i%
string$="'Twas brillig, and the slithy toves did gyre and gimble in the wabe."
i%=1
PRINT "Original string:"
PRINT " "+string$
PRINT :PRINT "Starting from 7th character and 23 length:"
PRINT " "+MID$(string$,7,23)
PRINT :PRINT "Starting from 50th character until end of string:"
PRINT " "+RIGHT$(string$,1+LEN(strintg$)-50)
PRINT :PRINT "Whole string minus the last character:"
PRINT LEFT$(string$,LEN(string$)-1)
PRINT :PRINT "Starting from character ""h"" and 9 length:"
WHILE MID$(string$,i%,1)<>"h"
i%=i%+1
ENDWH
PRINT " "+MID$(string$,i%,9)
PRINT :PRINT "Starting from substring ""the"" and 16 length:"
i%=1
WHILE MID$(string$,i%,3)<>"the"
i%=i%+1
ENDWH
PRINT " "+MID$(string$,i%,16)
GET
ENDP

View file

@ -0,0 +1,26 @@
require "uchar"
local s = uchar.of("αβγδεζηθ")
local n = 3
local m = 3
local kc = "δ" -- known character
local ks = "δε" -- known string
-- For reference.
print("Index of characters: 12345678")
print($"Complete string: {s}")
-- Starting from n characters in and of m length
print($"Start {n}, length {m}: {s:sub(n, n + m - 1)}")
-- Starting from n characters in, up to the end of the string
print($"Start {n}, to end: {s:sub(n)}")
-- Whole string minus last character.
print($"All but last: {s:sub(1, -2)}")
-- Starting from a known character within the string and of m length.
local dx = s:find(kc)
if dx then
print($"Start '{kc}', length {m}: {s:sub(dx, dx + m - 1)}")
end
-- Starting from a known substring within the string and of m length.
local sx = s:find(ks)
if sx then
print($"Start '{ks}', length {m}: {s:sub(sx, sx + m - 1)}")
end

View file

@ -0,0 +1,23 @@
# test string
$s = "abcdefgh"
# test parameters
$n, $m, $c, $s2 = 2, 3, [char]'d', $s2 = 'cd'
# starting from n characters in and of m length
# n = 2, m = 3
$s.Substring($n-1, $m) # returns 'bcd'
# starting from n characters in, up to the end of the string
# n = 2
$s.Substring($n-1) # returns 'bcdefgh'
# whole string minus last character
$s.Substring(0, $s.Length - 1) # returns 'abcdefg'
# starting from a known character within the string and of m length
# c = 'd', m =3
$s.Substring($s.IndexOf($c), $m) # returns 'def'
# starting from a known substring within the string and of m length
# s2 = 'cd', m = 3
$s.Substring($s.IndexOf($s2), $m) # returns 'cde'

View file

@ -0,0 +1,342 @@
# riscv assembly raspberry pico2 rp2350
# program substring.s
# connexion putty com3
/*********************************************/
/* CONSTANTES */
/********************************************/
/* for this file see risc-v task include a file */
.include "../../constantesRiscv.inc"
.equ BUFFERSIZE, 200
/*******************************************/
/* INITIALED DATAS */
/*******************************************/
.data
szMessStart: .asciz "Program riscv start.\r\n"
szMessEndOk: .asciz "Program riscv end OK.\r\n"
szCariageReturn: .asciz "\r\n"
szMessErrorString: .asciz "Error buffer size."
szMessString: .asciz "Result : "
szString1: .asciz "abcdefghijklmnopqrstuvwxyz"
szStringStart: .asciz "cdefg"
.align 2
/*******************************************/
/* UNINITIALED DATA */
/*******************************************/
.bss
sBuffer: .skip BUFFERSIZE
.align 2
/**********************************************/
/* SECTION CODE */
/**********************************************/
.text
.global main
main:
call stdio_init_all # général init
1: # start loop connexion
li a0,0 # raz argument register
call tud_cdc_n_connected # waiting for USB connection
beqz a0,1b # return code = zero ?
la a0,szMessStart # message address
call writeString # display message
la a0,szString1 # address string 1
la a1,sBuffer # result buffer
li a2,BUFFERSIZE # buffer size
li a3,10 # location
li a4,4 # size
call subStringNbChar #
bltz a0,100f # error
la a0,sBuffer # result buffer
call writeString # display message
la a0,szCariageReturn
call writeString
la a0,szString1 # address string 1
la a1,sBuffer # result buffer
li a2,BUFFERSIZE # buffer size
li a3,20 # location
li a4,1000 # size to end string
call subStringNbChar #
bltz a0,100f # error
la a0,sBuffer # result buffer
call writeString # display message
la a0,szCariageReturn
call writeString
la a0,szString1 # address string 1
la a1,sBuffer # result buffer
li a2,BUFFERSIZE # buffer size
call subStringMinus #
bltz a0,100f # error
la a0,sBuffer # result buffer
call writeString # display message
la a0,szCariageReturn
call writeString
la a0,szString1 # address string 1
la a1,sBuffer # result buffer
li a2,BUFFERSIZE # buffer size
li a3,'c' # character
li a4,5 # size to extract string
call subStringStChar # starting from a known character within the string and of m length
bltz a0,100f # error
la a0,sBuffer # result buffer
call writeString # display message
la a0,szCariageReturn
call writeString
la a0,szString1 # address string 1
la a1,sBuffer # result buffer
li a2,BUFFERSIZE # buffer size
la a3,szStringStart # string search address
li a4,5 # size to extract string
call subStringStString # starting from a substring within the string and of m length
li t0,-2
beq a0,t0,100f
la a0,sBuffer # result buffer
call writeString # display message
la a0,szCariageReturn
call writeString
la a0,szMessEndOk # message address
call writeString # display message
call getchar
100: # final loop
j 100b
/***************************************************/
/* extract n characters at location */
/***************************************************/
# a0 contains string
# a1 contains result area
# a2 contains size area result
# a3 contains location
# a4 contains length to extract
subStringNbChar:
addi sp, sp, -4 # reserve stack
sw ra, 0(sp) # save registers @ save registers
li t1,0 # init counter
li t2,0
1: # loop string1
add t0,a0,t1 # compute byte address
lbu t3,(t0) # load byte string
beqz t3,3f # zero final
bge t1,a3,2f # location ?
addi t1,t1,1 # no -> loop
j 1b
2:
add t0,a1,t2 # compute byte address result
sb t3,(t0) # store byte
addi t2,t2,1 # increment buffer indice
bgt t2,a2,99f # error ?
bge t2,a4,3f # end count extract ?
addi t1,t1,1 # no -> loop
j 1b
3:
add t0,a1,t2 # compute byte address
sb x0,(t0) # store zero final
mv a0,t2 # return extract length
j 100f
99: # error
la a0,szMessErrorString
call writeString # display message
li a0,-1 # error
100:
lw ra, 0(sp)
addi sp, sp, 4
ret
/***************************************************/
/* whole string minus last character */
/***************************************************/
# a0 contains string
# a1 contains result area
# a2 contanis size area result
subStringMinus:
addi sp, sp, -4 # reserve stack
sw ra, 0(sp) # save registers @ save registers
li t1,0 # init counter
li t2,0
1: # loop string1
add t0,a0,t1 # compute byte address
lbu t3,(t0) # load byte string
beqz t3,2f # zero final
add t0,a1,t2 # compute byte address result
sb t3,(t0) # store byte
addi t2,t2,1 # increment buffer indice
bgt t2,a2,99f # error ?
addi t1,t1,1 # no -> loop
j 1b
2:
addi t2,t2,-1
add t0,a1,t2 # compute byte address
sb x0,(t0) # store zero final
mv a0,t2 # return extract length
j 100f
99: # error
la a0,szMessErrorString
call writeString # display message
li a0,-1 # error
100:
lw ra, 0(sp)
addi sp, sp, 4
ret
/***************************************************/
/* extract n characters at location first character */
/***************************************************/
# a0 contains string
# a1 contains result area
# a2 contanis size area result
# a3 contains character
# a4 contains length to extract
subStringStChar:
addi sp, sp, -4 # reserve stack
sw ra, 0(sp) # save registers @ save registers
li t1,0 # init counter
li t2,0
1: # loop string1
add t0,a0,t1 # compute byte address
lbu t3,(t0) # load byte string
beqz t3,3f # zero final
beq t3,a3,2f # character ?
addi t1,t1,1 # no -> loop
j 1b
2:
add t0,a0,t1 # compute byte address
lbu t3,(t0) # load byte string
beqz t3,3f # zero final
add t0,a1,t2 # compute byte address result
sb t3,(t0) # store byte
addi t2,t2,1 # increment buffer indice
bgt t2,a2,99f # error ?
bge t2,a4,3f # end count extract ?
addi t1,t1,1 # no -> loop
j 2b
3:
add t0,a1,t2 # compute byte address
sb x0,(t0) # store zero final
mv a0,t2 # return extract length
j 100f
99: # error
la a0,szMessErrorString
call writeString # display message
li a0,-1 # error
100:
lw ra, 0(sp)
addi sp, sp, 4
ret
/***************************************************/
/* extract n characters at location search string */
/***************************************************/
# a0 contains string
# a1 contains result area
# a2 contanis size area result
# a3 contains adresse search string
# a4 contains length to extract
subStringStString:
addi sp, sp, -12 # reserve stack
sw ra,0(sp) # save registers
sw s0,4(sp)
sw s1,8(sp)
mv s0,a0
sb x0,(a1) # store 0 final in result area
mv s1,a1
mv a1,a3
call searchSubString
bltz a0,100f # not found
mv t1,a0 # init counter
li t2,0
1: # loop string1
add t0,s0,t1 # compute byte address
lbu t3,(t0) # load byte string
beqz t3,2f # zero final
add t0,s1,t2 # compute byte address result
sb t3,(t0) # store byte
addi t2,t2,1 # increment buffer indice
bgt t2,a2,99f # error ?
bge t2,a4,2f # end count extract ?
addi t1,t1,1 # no -> loop
j 1b
2:
add t0,s1,t2 # compute byte address
sb x0,(t0) # store zero final
mv a0,t2 # return extract length
j 100f
10:
li a0,-1
j 100f
99: # error
la a0,szMessErrorString
call writeString # display message
li a0,-1 # error
100:
lw ra, 0(sp)
lw s0,4(sp)
lw s1,8(sp)
addi sp, sp, 12
ret
/***************************************************/
/* search string in string */
/***************************************************/
# a0 contains string
# a1 contains search string
# a0 returns indice if find or -1 if not or -2 if error
searchSubString:
addi sp, sp, -4 # reserve stack
sw ra, 0(sp) # save registers @ save registers
li t3,0
1:
li t5,-1 # indice find ok
li t1,0 # init counter
add t0,a1,t1 # compute byte address
lbu t2,(t0) # load byte string
beqz t2,99f # empty string -> error
2: # loop to copy string begin
add t0,a0,t3 # compute byte address string 1
lbu t4,(t0) # load byte string
beqz t4,5f # zero final ?
bne t4,t2,3f # not equal
addi t5,t5,1 # increment indice find
addi t3,t3,1 # increment indice string
addi t1,t1,1 # increment indice search string
add t0,a1,t1 # compute byte address
lbu t2,(t0) # load byte string
beqz t2,6f # end search string -> found
j 2b # else loop
3:
bltz t5,4f # not characters precedent found ?
sub t3,t3,t5 # yes raz position search
j 1b # and restart search at begining
4:
addi t3,t3,1 # increment indice
j 2b # and loop other character
5:
li a0,-1 # not found
j 100f
6:
mv a0,t3 # return end indice
j 100f
99: # error
la a0,szMessErrorString
call writeString # display message
li a0,-2 # error
100:
lw ra, 0(sp)
addi sp, sp, 4
ret
/************************************/
/* file include Fonctions */
/***********************************/
/* for this file see risc-v task include a file */
.include "../../includeFunctions.s"

View file

@ -0,0 +1,12 @@
let s = "ABCDEFGH"
let from = 2
let length = 3
Js.log2("Original string: ", s)
Js.log(Js.String.substrAtMost(~from, ~length, s))
Js.log(Js.String.substr(~from, s))
Js.log(Js.String.substrAtMost(~from=0, ~length=(Js.String2.length(s) - 1), s))
Js.log(Js.String.substrAtMost(~from=(Js.String.indexOf("B", s)), ~length, s))
Js.log(Js.String.substrAtMost(~from=(Js.String.indexOf("BC", s)), ~length, s))

View file

@ -0,0 +1,41 @@
Rebol [
Title: "Retrieve Substring"
URL: http://rosettacode.org/wiki/Substring#Rebol
]
s: "abcdefgh" n: 2 m: 3 char: #"d" chars: "cd"
; Note that REBOL uses base-1 indexing. Strings are series values,
; just like blocks or lists so I can use the same words to manipulate
; them. All these examples use the 'copy' function against the 's'
; string with a particular offset as needed.
; For the fragment "copy/part skip s n - 1 m", read from right to
; left. First you have 'm', which we ignore for now. Then evaluate
; 'n - 1' (makes 1), to adjust the offset. Then 'skip' jumps from the
; start of the string by that offset. 'copy' starts copying from the
; new start position and the '/part' refinement limits the copy by 'm'
; characters.
print ["Starting from n, length m:"
copy/part skip s n - 1 m]
; It may be helpful to see the expression with optional parenthesis:
print ["Starting from n, length m (parens):"
(copy/part (skip s (n - 1)) m)]
; This example is much simpler, so hopefully it's easier to see how
; the string start is position for the copy:
print ["Starting from n to end of string:"
copy skip s n - 1]
print ["Whole string minus last character:"
copy/part s (length? s) - 1]
print ["Starting from known character, length m:"
copy/part find s char m]
print ["Starting from substring, length m:"
copy/part find s chars m]

View file

@ -0,0 +1,16 @@
s = "rosettacode.org"
'starting from n characters in and of m length
WScript.StdOut.WriteLine Mid(s,8,4)
'starting from n characters in, up to the end of the string
WScript.StdOut.WriteLine Mid(s,8,Len(s)-7)
'whole string minus last character
WScript.StdOut.WriteLine Mid(s,1,Len(s)-1)
'starting from a known character within the string and of m length
WScript.StdOut.WriteLine Mid(s,InStr(1,s,"c"),4)
'starting from a known substring within the string and of m length
WScript.StdOut.WriteLine Mid(s,InStr(1,s,"ose"),6)