task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Raku
Raku
sub sum35($n) { [+] grep * %% (3|5), ^$n; }   say sum35 1000;
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#Scheme
Scheme
  (import (scheme base) (scheme write))   ;; convert number to a list of digits, in desired base (define (number->list n base) (let loop ((res '()) (num n)) (if (< num base) (cons num res) (loop (cons (remainder num base) res) (quotient num base)))))   ;; return the ...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#SQL
SQL
SELECT SUM(x*x) FROM vector
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Standard_ML
Standard ML
foldl (fn (a, sum) => sum + a * a) 0 ints
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Standard_ML
Standard ML
local open Substring in val trimLeft = string o dropl Char.isSpace o full and trimRight = string o dropr Char.isSpace o full and trim = string o dropl Char.isSpace o dropr Char.isSpace o full end
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Stata
Stata
s = " ars longa " "("+strtrim(s)+")" (ars longa)   "("+strltrim(s)+")" (ars longa )   "("+strrtrim(s)+")" ( ars longa)   "("+stritrim(s)+")" ( ars longa )
http://rosettacode.org/wiki/Substring
Substring
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Lua
Lua
str = "abcdefghijklmnopqrstuvwxyz" n, m = 5, 15   print( string.sub( str, n, m ) ) -- efghijklmno print( string.sub( str, n, -1 ) ) -- efghijklmnopqrstuvwxyz print( string.sub( str, 1, -2 ) ) -- abcdefghijklmnopqrstuvwxy   pos = string.find( str, "i" ) if pos ~= nil then print( string.sub( str, pos, pos+m ) ) en...
http://rosettacode.org/wiki/Sudoku
Sudoku
Task Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format. references Algorithmics of Sudoku   may help implement this. Python Sudoku Solver Computerphile video.
#Rust
Rust
type Sudoku = [u8; 81];   fn is_valid(val: u8, x: usize, y: usize, sudoku_ar: &mut Sudoku) -> bool { (0..9).all(|i| sudoku_ar[y * 9 + i] != val && sudoku_ar[i * 9 + x] != val) && { let (start_x, start_y) = ((x / 3) * 3, (y / 3) * 3); (start_y..start_y + 3).all(|i| (start_x..start_x + 3).all(|j| sudo...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#Ruby
Ruby
puts "knight"[1..-1] # strip first character puts "socks"[0..-2] # strip last character puts "socks".chop # alternate way to strip last character puts "brooms"[1..-2] # strip both first and last characters puts "与今令"[1..-2] # => 今
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#Run_BASIC
Run BASIC
s$ = "Run BASIC" print mid$(s$,2) 'strip first print left$(s$,len(s$) -1) 'strip last print mid$(s$,2,len(s$) -2) 'strip first and last
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Python
Python
numbers = [1, 2, 3] total = sum(numbers)   product = 1 for i in numbers: product *= i
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#MMIX
MMIX
x IS $1 % flt calculations y IS $2 % id z IS $3 % z = sum series t IS $4 % temp var   LOC Data_Segment GREG @ BUF OCTA 0,0,0 % print buffer   LOC #1000 GREG @ // print floating point number in scientific format: 0.xxx...ey.. // most of this routine is adopted from: // http://www.pspu.ru/personal/eremin/emmi/ro...
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Stata
Stata
: printf("Mary had a %s lamb.\n", "little") Mary had a little lamb.
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Swift
Swift
let extra = "little" println("Mary had a \(extra) lamb.")
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#Ring
Ring
  aList = "She was a soul stripper. She took my heart!" bList = "aei" see aList + nl see stripChars(aList,bList)   func stripChars cList, dList for n = 1 to len(dList) cList = substr(cList,dList[n],"") + nl next return cList  
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#Ruby
Ruby
"She was a soul stripper. She took my heart!".delete("aei") # => "Sh ws soul strppr. Sh took my hrt!"
http://rosettacode.org/wiki/String_comparison
String comparison
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Raku
Raku
sub compare($a,$b) { my $A = "{$a.WHAT.^name} '$a'"; my $B = "{$b.WHAT.^name} '$b'";   if $a eq $b { say "$A and $B are lexically equal" } if $a ne $b { say "$A and $B are not lexically equal" }   if $a gt $b { say "$A is lexically after $B" } if $a lt $b { say "$A is lexically before than $B" }...
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#M4
M4
define(`upcase', `translit(`$*', `a-z', `A-Z')') define(`downcase', `translit(`$*', `A-Z', `a-z')')   define(`x',`alphaBETA') upcase(x) downcase(x)
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Maple
Maple
str := "alphaBETA"; StringTools:-UpperCase(str); StringTools:-LowerCase(str);
http://rosettacode.org/wiki/String_matching
String matching
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#LabVIEW
LabVIEW
  {def S.in {def S.in.r {lambda {:c :w :i :n} {if {= :i :n} then -1 else {if {W.equal? :c {W.get :i :w}} then :i else {S.in.r :c :w {+ :i 1} :n}}}}} {lambda {:c :w} {S.in.r :c :w 0 {W.length :w}}}} -> S.in       {def startswith {lambda {:w1 :w2} {= {S.in _ {S.replace :w2 by _ in :w1}} 0}}} ...
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#Java
Java
String s = "Hello, world!"; int byteCountUTF16 = s.getBytes("UTF-16").length; // Incorrect: it yields 28 (that is with the BOM) int byteCountUTF16LE = s.getBytes("UTF-16LE").length; // Correct: it yields 26 int byteCountUTF8 = s.getBytes("UTF-8").length; // yields 13
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task 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 operat...
#Objective-C
Objective-C
#import <Foundation/Foundation.h>   int main() { @autoreleasepool {   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]); ...
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#REXX
REXX
/* REXX *************************************************************** * 14.05.2013 Walter Pachl **********************************************************************/ Say mul35() exit mul35: s=0 Do i=1 To 999 If i//3=0 | i//5=0 Then s=s+i End Return s
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#Seed7
Seed7
$ include "seed7_05.s7i";   const func integer: sumDigits (in var integer: num, in integer: base) is func result var integer: sum is 0; begin while num > 0 do sum +:= num rem base; num := num div base; end while; end func;   const proc: main is func begin writeln(sumDigits(1, 1...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Stata
Stata
a = 1..100 sum(a:^2) 338350   a = J(0, 1, .) length(a) 0 sum(a:^2) 0
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Tcl
Tcl
set str " hello world " puts "original: >$str<" puts "trimmed head: >[string trimleft $str]<" puts "trimmed tail: >[string trimright $str]<" puts "trimmed both: >[string trim $str]<"
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#TI-83_BASIC
TI-83 BASIC
  PROGRAM:WHITESPC Input Str1 0→M Menu(" REMOVE ","TRAILIN WHTSPC",A,"LEADING WHTSPC",C,"BOTH",B)   Lbl B 1→M   Lbl A While sub(Str1,length(Str1)-1),1)=" " sub(Str1,1,length(Str1)-1)→Str1 End   If M=1 Then Goto C Else Goto F End   Lbl C While sub(str1,1,1)=" " sub(Str1,2,length(Str1)-1)→Str1 End   Lbl F Disp "'...
http://rosettacode.org/wiki/Substring
Substring
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#M2000_Interpreter
M2000 Interpreter
  Module CheckAnsi { \\ ANSI STRING Locale 1033 \\ convert UTF16-LE to ANSI 8bit s$ =Str$("ABCDEFG") Print Len(s$)=3.5 ' 3.5 words, means 7 bytes (3.5*2) AnsiLen=Len(s$)*2 ' From 4th byte get 3 bytes n=4 m=3 substring$=Mid$(s$, n, m as byte) substring2E...
http://rosettacode.org/wiki/Sudoku
Sudoku
Task Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format. references Algorithmics of Sudoku   may help implement this. Python Sudoku Solver Computerphile video.
#SAS
SAS
/* define SAS data set */ data Indata; input C1-C9; datalines; . . 5 . . 7 . . 1 . 7 . . 9 . . 3 . . . . 6 . . . . . . . 3 . . 1 . . 5 . 9 . . 8 . . 2 . 1 . . 2 . . 4 . . . . 2 . . 6 . . 9 . . . . 4 . . 8 . 8 . . 1 . . 5 . . ;   /* call OPTMODEL procedure in SAS/OR */ proc optmodel; /* declare variables */ ...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#Rust
Rust
fn main() { let s = String::from("žluťoučký kůň");   let mut modified = s.clone(); modified.remove(0); println!("{}", modified);   let mut modified = s.clone(); modified.pop(); println!("{}", modified);   let mut modified = s; modified.remove(0); modified.pop(); println!("{}"...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#Scala
Scala
println("knight".tail) // strip first character println("socks".init) // strip last character println("brooms".tail.init) // strip both first and last characters
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#QBasic
QBasic
DIM array(1 TO 5) DATA 1, 2, 3, 4, 5 FOR index = LBOUND(array) TO UBOUND(array) READ array(index) NEXT index   LET sum = 0 LET prod = 1 FOR index = LBOUND(array) TO UBOUND(array) LET sum = sum + array(index) LET prod = prod * array(index) NEXT index PRINT "The sum is "; sum PRINT "and the product is "; prod...
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Modula-2
Modula-2
MODULE SeriesSum; FROM InOut IMPORT WriteLn; FROM RealInOut IMPORT WriteReal;   TYPE RealFunc = PROCEDURE (REAL): REAL;   PROCEDURE seriesSum(k, n: CARDINAL; f: RealFunc): REAL; VAR total: REAL; i: CARDINAL; BEGIN total := 0.0; FOR i := k TO n DO total := total + f(FLOAT(i)); END; RE...
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Tailspin
Tailspin
  def size: 'little'; 'Mary had a $size; lamb' -> !OUT::write  
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Tcl
Tcl
set size "little" puts "Mary had a $size lamb."   proc RandomWord {args} { lindex $args [expr {int(rand()*[llength $args])}] } puts "Mary had a [RandomWord little big] lamb."
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT   sentence_old="Mary had a X lamb."   values=* DATA little DATA big   sentence_new=SUBSTITUTE (sentence_old,":X:",0,0,values) PRINT sentence_old PRINT sentence_new  
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#Run_BASIC
Run BASIC
function stripchars(texto, remove) s = texto for i = 1 to length(remove) s = replace(s, mid(remove, i, 1), "", true) next i   return s end function
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#Rust
Rust
  fn strip_characters(original : &str, to_strip : &str) -> String { let mut result = String::new(); for c in original.chars() { if !to_strip.contains(c) { result.push(c); } } result }  
http://rosettacode.org/wiki/String_comparison
String comparison
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Relation
Relation
  set a = "Hello" set b = "World" if a == b ' a is equal to b (case sensitive) end if if lower(a) == lower(b) ' a is equal to b (case insensitive) end if if a !== b ' a is not equal to b (case sensitive) end if if lower(a) !== lower(b) ' a is not equal to b (case insensitive) end if if a << b ' a is lexically first to ...
http://rosettacode.org/wiki/String_comparison
String comparison
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#REXX
REXX
/*REXX program shows different ways to compare two character strings.*/ say 'This is an ' word('ASCII EBCDIC', 1+(1=='f1')) ' system.' say cat = 'cat' animal = 'dog' if animal = cat then say $(animal) "is lexically equal to" $(cat) if animal \= cat then say $(animal) "is not lexically ...
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
str="alphaBETA"; ToUpperCase[str] ToLowerCase[str]
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#MATLAB_.2F_Octave
MATLAB / Octave
>> upper('alphaBETA')   ans =   ALPHABETA   >> lower('alphaBETA')   ans =   alphabeta
http://rosettacode.org/wiki/String_matching
String matching
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Lambdatalk
Lambdatalk
  {def S.in {def S.in.r {lambda {:c :w :i :n} {if {= :i :n} then -1 else {if {W.equal? :c {W.get :i :w}} then :i else {S.in.r :c :w {+ :i 1} :n}}}}} {lambda {:c :w} {S.in.r :c :w 0 {W.length :w}}}} -> S.in       {def startswith {lambda {:w1 :w2} {= {S.in _ {S.replace :w2 by _ in :w1}} 0}}} ...
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#JavaScript
JavaScript
var s = "Hello, world!"; var byteCount = s.length * 2; //26
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task 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 operat...
#OCaml
OCaml
let s = "hello" let s1 = s ^ " literal" let () = print_endline (s ^ " literal"); print_endline s1
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task 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 operat...
#Oforth
Oforth
"Hello" dup " World!" + .s
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task 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 operat...
#Openscad
Openscad
a="straw"; b="berry"; c=str(a,b); /* Concatenate a and b */ echo (c);
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Ring
Ring
  see sum35(1000) + nl   func sum35 n n = n - 1 return(3 * tri(floor(n / 3)) + 5 * tri(floor(n / 5)) - 15 * tri(floor(n / 15)))   func tri n return n * (n + 1) / 2  
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#Sidef
Sidef
func Σ(String str, base=36) { str.chars.map{ Num(_, base) }.sum }   <1 1234 1020304 fe f0e DEADBEEF>.each { |n| say "Σ(#{n}) = #{Σ(n)}" }
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Swift
Swift
func sumSq(s: [Int]) -> Int { return s.map{$0 * $0}.reduce(0, +) }
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Tailspin
Tailspin
  templates ssq when <[](0)> do 0 ! otherwise $... -> $*$ -> ..=Sum&{of: :()} ! end ssq   [] -> ssq -> !OUT::write // outputs 0 [1..5] -> ssq -> !OUT::write // outputs 55  
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#TorqueScript
TorqueScript
$string = " yep "; $string = LTrim($string); echo($string);
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#TUSCRIPT
TUSCRIPT
$$ MODE TUSCRIPT str= " sentence w/whitespace before and after " trimmedtop=EXTRACT (str,":<|<> :"|,0) trimmedtail=EXTRACT (str,0,":<> >|:") trimmedboth=SQUEEZE(str) PRINT "string <|", str," >|" PRINT "trimmed on top <|",trimmedtop,">|" PRINT "trimmed on tail <|", trimmedtail,">|" PRINT "trimmed on...
http://rosettacode.org/wiki/Substring
Substring
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Maple
Maple
  > n, m := 3, 5: > s := "The Higher, The Fewer!": > s[ n .. n + m - 1 ]; "e Hig"  
http://rosettacode.org/wiki/Substring
Substring
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
n = 2 m = 3 StringTake["Mathematica", {n+1, n+m-1}] StringDrop["Mathematica", n] (* StringPosition returns a list of starting and ending character positions for a substring *) pos = StringPosition["Mathematica", "e"][[1]][[1]] StringTake["Mathematica", {pos, pos+m-1}] (* Similar to above *) pos = StringPosition["Mathem...
http://rosettacode.org/wiki/Sudoku
Sudoku
Task Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format. references Algorithmics of Sudoku   may help implement this. Python Sudoku Solver Computerphile video.
#Scala
Scala
object SudokuSolver extends App {   class Solver {   var solution = new Array[Int](81) //listOfFields toArray   val fp2m: Int => Tuple2[Int,Int] = pos => Pair(pos/9+1,pos%9+1) //get row, col from array position val setAll = (1 to 9) toSet //all possibilities   val arrayGroups = new Array[List[List[I...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#Scheme
Scheme
(define (string-top s) (if (string=? s "") s (substring s 0 (- (string-length s) 1))))   (define (string-tail s) (if (string=? s "") s (substring s 1 (string-length s))))   (define (string-top-tail s) (string-tail (string-top s)))
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Quackery
Quackery
[ 0 swap witheach + ] is sum ( [ --> n )   [ 1 swap witheach * ] is product ( [ --> n )
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#R
R
total <- sum(1:5) product <- prod(1:5)
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Modula-3
Modula-3
MODULE Sum EXPORTS Main;   IMPORT IO, Fmt, Math;   VAR sum: LONGREAL := 0.0D0;   PROCEDURE F(x: LONGREAL): LONGREAL = BEGIN RETURN 1.0D0 / Math.pow(x, 2.0D0); END F;   BEGIN FOR i := 1 TO 1000 DO sum := sum + F(FLOAT(i, LONGREAL)); END; IO.Put("Sum of F(x) from 1 to 1000 is "); IO.Put(Fmt.LongReal(s...
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#UNIX_Shell
UNIX Shell
extra='little' echo Mary had a $extra lamb. echo "Mary had a $extra lamb." printf "Mary had a %s lamb.\n" $extra
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Ursala
Ursala
-[foo-[ x ]-bar]-
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Vala
Vala
void main() { string size = "little"; print(@"Mary had a $size lamb\n"); stdout.printf("Mary had a %s lamb\n", size); }
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#SAS
SAS
%let string=She was a soul stripper. She took my heart!; %let chars=aei; %let stripped=%sysfunc(compress("&string","&chars")); %put &stripped;
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#Scala
Scala
def stripChars(s:String, ch:String)= s filterNot (ch contains _)   stripChars("She was a soul stripper. She took my heart!", "aei") // => Sh ws soul strppr. Sh took my hrt!
http://rosettacode.org/wiki/String_comparison
String comparison
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Ring
Ring
    if s1 = s2 See "The strings are equal" ok if not (s1 = s2) See "The strings are not equal" ok if strcmp(s1,s2) > 0 see "s2 is lexically ordered before than s1" ok if strcmp(s1,s2) < 0 see "s2 is lexically ordered after than s1" ok   To achieve case insensitive compari...
http://rosettacode.org/wiki/String_comparison
String comparison
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Robotic
Robotic
  set "$str1" to "annoy" set "$str2" to "annoy" : "loop" if "$str1" === "$str2" then "case_equal" if "$str1" = "$str2" then "equal" if "$str1" > "$str2" then "greater_than" if "$str1" < "$str2" then "less_than" end   : "case_equal" * "&$str1& is case equal to &$str2&" set "$str2" to "ANNOY" goto "loop"   : "equal" * "&...
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Maxima
Maxima
supcase('alphaBETA'); sdowncase('alphaBETA');
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#MAXScript
MAXScript
str = "alphaBETA" print (toUpper str) print (toLower str)
http://rosettacode.org/wiki/String_matching
String matching
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Lang5
Lang5
: 2array 2 compress ; : bi* '_ set dip _ execute ;  : bi@ dup bi* ; : comb "" split ;  : concat "" join ;  : dip swap '_ set execute _ ; : first 0 extract swap drop ; : flip comb reverse concat ;   : contains swap 'comb bi@ length do # create a matrix. 1 - "dup 1 1 compress rotat...
http://rosettacode.org/wiki/String_matching
String matching
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Lasso
Lasso
local( a = 'a quick brown peanut jumped over a quick brown fox', b = 'a quick brown' )   //Determining if the first string starts with second string #a->beginswith(#b) // true   //Determining if the first string contains the second string at any location #a >> #b // true #a->contains(#b) // true   //Deter...
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#jq
jq
$ cat String_length.jq def describe: "length of \(.) is \(length)";   ("J̲o̲s̲é̲", "𝔘𝔫𝔦𝔠𝔬𝔡𝔢") | describe
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#JudoScript
JudoScript
//Store length of hello world in length and print it . length = "Hello World".length();
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task 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 operat...
#Oz
Oz
declare S = "hello" {System.showInfo S#" literal"} %% virtual strings are constructed with "#" S1 = {Append S " literal"} {System.showInfo S1}
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task 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 operat...
#PARI.2FGP
PARI/GP
s = "Hello "; s = Str(s, "world"); \\ Alternately, this could have been: \\ s = concat(s, "world"); print(s);
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task 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 operat...
#Pascal
Pascal
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.
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Ruby
Ruby
def sum35(n) (1...n).select{|i|i%3==0 or i%5==0}.sum end puts sum35(1000) #=> 233168
http://rosettacode.org/wiki/Sum_digits_of_an_integer
Sum digits of an integer
Task Take a   Natural Number   in a given base and return the sum of its digits:   110         sums to   1   123410   sums to   10   fe16       sums to   29   f0e16     sums to   29
#SQL
SQL
  /* This code is an implementation of "Sum digits of an integer" in SQL ORACLE 19c p_in_str -- input string */ WITH FUNCTION sum_digits(p_in_str IN varchar2) RETURN varchar2 IS v_in_str VARCHAR(32767) := translate(p_in_str,'*-+','*'); v_sum INTEGER; BEGIN -- IF regexp_count(v_in_str,'[0-9A-F]',1,'i')=LENGTH...
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Tcl
Tcl
package require Tcl 8.6 namespace path ::tcl::mathop   # {*} is like apply in Scheme--it turns a list into multiple arguments proc sum_of_squares lst { + {*}[lmap x $lst {* $x $x}] } puts [sum_of_squares {1 2 3 4}]; # ==> 30 puts [sum_of_squares {}]; # ==> 0  
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Trith
Trith
[3 1 4 1 5 9] 0 [dup * +] foldl
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#TXR
TXR
@(define trim_left (in out)) @ (next :list in) @/[ \t]*/@out @(end) @(define trim_right (in out)) @ (local blanks middle) @ (next :list in) @ (cases) @ {blanks /[ \t]*/}@middle@/[\t ]+/ @ (bind out `@blanks@middle`) @ (or) @ out @ (end) @(end) @line_of_input @(output) trim-left: [@{line_of_input :filter...
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Ursala
Ursala
#import std   white = ==` !| not @iNC %sI trim_left = white-~r trim_right = white~-l trim_both = trim_left+ trim_right   #cast %sgUL   main = <.trim_left,trim_right,trim_both> ' string with spaces '
http://rosettacode.org/wiki/Substring
Substring
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#MATLAB_.2F_Octave
MATLAB / Octave
  % starting from n characters in and of m length; s(n+(1:m)) s(n+1:n+m) % starting from n characters in, up to the end of the string; s(n+1:end) % whole string minus last character; s(1:end-1) % starting from a known character within the string and of m length; s...
http://rosettacode.org/wiki/Sudoku
Sudoku
Task Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format. references Algorithmics of Sudoku   may help implement this. Python Sudoku Solver Computerphile video.
#Scilab
Scilab
Init_board=[... 5 3 0 0 7 0 0 0 0;... 6 0 0 1 9 5 0 0 0;... 0 9 8 0 0 0 0 6 0;... 8 0 0 0 6 0 0 0 3;... 4 0 0 8 0 3 0 0 1;... 7 0 0 0 2 0 0 0 6;... 0 6 0 0 0 0 2 8 0;... 0 0 0 4 1 9 0 0 5;... 0 0 0 0 8 0 0 7 9];   break_point=1.0d5; //if 0 there will be no break   function []=disp_board(board) StringBoard=string(bo...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func local const string: stri is "upraisers"; begin writeln("Full string: " <& stri); writeln("Without first: " <& stri[2 ..]); writeln("Without last: " <& stri[.. pred(length(stri))]); writeln("Without both: " <& stri[2 .. pred(length(stri))])...
http://rosettacode.org/wiki/Substring/Top_and_tail
Substring/Top and tail
The task is to demonstrate how to remove the first and last characters from a string. The solution should demonstrate how to obtain the following results: String with first character removed String with last character removed String with both the first and last characters removed If the program uses UTF-8 or UTF...
#SenseTalk
SenseTalk
  set message to peaceSymbol & "Peace!" put message put characters second to last of message put characters 1 to -2 of message put the second to penultimate characters of message  
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Racket
Racket
#lang racket   (for/sum ([x #(3 1 4 1 5 9)]) x) (for/product ([x #(3 1 4 1 5 9)]) x)
http://rosettacode.org/wiki/Sum_and_product_of_an_array
Sum and product of an array
Task Compute the sum and product of an array of integers.
#Raku
Raku
my @ary = 1, 5, 10, 100; say 'Sum: ', [+] @ary; say 'Product: ', [*] @ary;
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#MUMPS
MUMPS
  SOAS(N) NEW SUM,I SET SUM=0 FOR I=1:1:N DO .SET SUM=SUM+(1/((I*I))) QUIT SUM  
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#VBA
VBA
a="little" debug.print replace("Mary had a X lamb","X",a) 'prints Mary had a little lamb
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Verbexx
Verbexx
//////////////////////////////////////////////////////////////////////////////////////// // // The @INTERPOLATE verb processes a string with imbedded blocks of code. The code // blocks are parsed and evaluated. Any results are converted to a string, which // is then inserted into the output string, replacing the ...
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Visual_Basic_.NET
Visual Basic .NET
  Dim name as String = "J. Doe" Dim balance as Double = 123.45 Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance) Console.WriteLine(prompt)  
http://rosettacode.org/wiki/Strip_a_set_of_characters_from_a_string
Strip a set of characters from a string
Task Create a function that strips a set of characters from a string. The function should take two arguments:   a string to be stripped   a string containing the set of characters to be stripped The returned string should contain the first string, stripped of any characters in the second argument: print str...
#Scheme
Scheme
  (import (scheme base) (scheme write) (only (srfi 13) string-delete) (only (srfi 14) ->char-set))   ;; implementation in plain Scheme (define (strip-chars str chars) (let ((char-list (string->list chars))) (define (do-strip str-list result) (cond ((null? str-list) (reve...
http://rosettacode.org/wiki/String_comparison
String comparison
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Ruby
Ruby
method_names = [:==,:!=, :>, :>=, :<, :<=, :<=>, :casecmp] [["YUP", "YUP"], ["YUP", "Yup"], ["bot","bat"], ["aaa", "zz"]].each do |str1, str2| method_names.each{|m| puts "%s %s %s\t%s" % [str1, m, str2, str1.send(m, str2)]} puts end
http://rosettacode.org/wiki/String_comparison
String comparison
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Run_BASIC
Run BASIC
a$ = "dog" b$ = "cat" if a$ = b$ then print "the strings are equal" ' test for equalitY if a$ <> b$ then print "the strings are not equal" ' test for inequalitY if a$ > b$ then print a$;" is lexicallY higher than ";b$ ' test for lexicallY higher if a$ < b$ then print a$;" is lexicallY lower than ";b$ ' test f...
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Mercury
Mercury
:- module string_case. :- interface.   :- import_module io. :- pred main(io::di, io::uo) is det.   :- implementation. :- import_module list, string.   main(!IO) :- S = "alphaBETA", io.format("uppercase  : %s\n", [s(to_upper(S))], !IO), io.format("lowercase  : %s\n", [s(to_lower(S))], !IO), io.form...
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Metafont
Metafont
vardef isbetween(expr a, i, f) = if string a: if (ASCII(a) >= ASCII(i)) and (ASCII(a) <= ASCII(f)): true else: false fi else: false fi enddef;   vardef toupper(expr s) = save ?; string ?; ? := ""; d := ASCII"A" - ASCII"a"; for i = 0 upto length(s)-1: if isbetween(substring(i, i...
http://rosettacode.org/wiki/String_matching
String matching
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Liberty_BASIC
Liberty BASIC
'1---Determining if the first string starts with second string st1$="first string" st2$="first" if left$(st1$,len(st2$))=st2$ then print "First string starts with second string." end if   '2---Determining if the first string contains the second string at any location '2.1---Print the location of the match for part ...
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#Julia
Julia
sizeof("Hello, world!") # gives 13 sizeof("Hellö, wørld!") # gives 15
http://rosettacode.org/wiki/String_length
String length
Task Find the character and byte length of a string. This means encodings like UTF-8 need to be handled properly, as there is not necessarily a one-to-one relationship between bytes and characters. By character, we mean an individual Unicode code point, not a user-visible grapheme containing combining characters. F...
#K
K
  #"Hello, world!" 13 #"Hëllo, world!" 13