update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
25
Task/Substring/Racket/substring.rkt
Normal file
25
Task/Substring/Racket/substring.rkt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#lang racket
|
||||
|
||||
(define str "abcdefghijklmnopqrstuvwxyz")
|
||||
|
||||
(define n 10)
|
||||
(define m 2)
|
||||
(define start-char #\x)
|
||||
(define start-str "xy")
|
||||
|
||||
;; starting from n characters in and of m length;
|
||||
(substring str n (+ n m)) ; -> "kl"
|
||||
|
||||
;; starting from n characters in, up to the end of the string;
|
||||
(substring str m) ; -> "klmnopqrstuvwxyz"
|
||||
|
||||
;; whole string minus last character;
|
||||
(substring str 0 (sub1 (string-length str))) ; -> "abcdefghijklmnopqrstuvwxy"
|
||||
|
||||
;; starting from a known character within the string and of m length;
|
||||
(substring str (caar (regexp-match-positions (regexp-quote (string start-char))
|
||||
str))) ; -> "xyz"
|
||||
|
||||
;; starting from a known substring within the string and of m length.
|
||||
(substring str (caar (regexp-match-positions (regexp-quote start-str)
|
||||
str))) ; -> "xyz"
|
||||
26
Task/Substring/Raven/substring.raven
Normal file
26
Task/Substring/Raven/substring.raven
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
define println use $s
|
||||
$s print "\n" print
|
||||
|
||||
"0123456789" as $str
|
||||
|
||||
$str 3 2 extract println # at 4th pos get 2 chars
|
||||
$str 8 4 extract println # at 9th pos get 4 chars (when only 1 char available)
|
||||
|
||||
|
||||
$str 3 $str length extract println # at 4th pos get all chars to end of str
|
||||
$str 3 0x7FFFFFFF extract println # at 4th pos get all chars to end of str
|
||||
|
||||
$str 3 -1 extract println # at 4th pos get rest of chars but last one
|
||||
$str 0 -1 extract println # all chars but last one
|
||||
|
||||
"3" as $matchChr # starting chr for extraction
|
||||
4 as $subLen # Nr chars after found starting char
|
||||
$str $matchChr split as $l
|
||||
"" $l 0 set $l $matchChr join
|
||||
0 $subLen extract println
|
||||
|
||||
"345" as $matchChrs # starting chrs for extraction
|
||||
6 as $subLen # Nr chars after found starting chars
|
||||
$str $matchChrs split as $l
|
||||
"" $l 0 set $l $matchChrs join
|
||||
0 $subLen extract println
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
str = 'abcdefgh'
|
||||
n = 2
|
||||
m = 3
|
||||
puts str[n, m]
|
||||
puts str[n..-1]
|
||||
puts str[0..-2]
|
||||
puts str[str.index('d'), m]
|
||||
puts str[str.index('de'), m]
|
||||
puts str[/a.*d/]
|
||||
puts str[n, m] #=> cde
|
||||
puts str[n..m] #=> cd
|
||||
puts str[n..-1] #=> cdefgh
|
||||
puts str[0..-2] #=> abcdefg
|
||||
puts str[str.index('d'), m] #=> def
|
||||
puts str[str.index('de'), m] #=> def
|
||||
puts str[/a.*d/] #=> abcd
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue