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/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... | #Perl | Perl | my $s = 'hello';
print $s . ' literal', "\n";
my $s1 = $s . ' literal';
print $s1, "\n"; |
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... | #Phix | Phix | string s1 = "at" ?s1
string s2 = "c"&s1 ?s2
string s3 = "s"&s1 ?s3
string s4 = "m"&s1 ?s4
string s5 = "The "&s2&" "&s3&" on the "&s4&"." ?s5
|
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.
| #Run_BASIC | Run BASIC | print multSum35(1000)
end
function multSum35(n)
for i = 1 to n - 1
If (i mod 3 = 0) or (i mod 5 = 0) then multSum35 = multSum35 + i
next i
end function |
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
| #Standard_ML | Standard ML | fun sumDigits (0, _) = 0
| sumDigits (n, base) = n mod base + sumDigits (n div base, base)
val testInput = [(1, 10), (1234, 10), (0xfe, 16), (0xf0e, 16)]
val () = print (String.concatWith " " (map (Int.toString o sumDigits) testInput) ^ "\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
| #TUSCRIPT | TUSCRIPT |
$$ MODE TUSCRIPT
array="3'1'4'1'5'9",sum=0
LOOP a=array
sum=sum+(a*a)
ENDLOOP
PRINT sum
|
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
| #UnixPipes | UnixPipes | folder() {
(read B; res=$( expr $1 \* $1 ) ; test -n "$B" && expr $res + $B || echo $res)
}
fold() {
(while read a ; do
fold | folder $a
done)
}
(echo 3; echo 1; echo 4;echo 1;echo 5; echo 9) | fold |
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... | #Vala | Vala | string s = " word ";
string s_chug = s.chug(); |
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... | #VBA | VBA | Public Sub test()
'LTrim trims leading spaces
'RTrim trims tailing spaces
'Trim trims both leading and tailing spaces
s = " trim "
Debug.Print """" & s & """"
Debug.Print """" & LTrim(s) & """"
Debug.Print """" & RTrim(s) & """"
Debug.Print """" & WorksheetFunction.trim(s) & """"
'th... |
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 |... | #Maxima | Maxima | s: "the quick brown fox jumps over the lazy dog";
substring(s, 17);
/* "fox jumps over the lazy dog" */
substring(s, 17, 20);
/* "fox" */ |
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.
| #Sidef | Sidef | func check(i, j) is cached {
var (id, im) = i.divmod(9)
var (jd, jm) = j.divmod(9)
jd == id && return true
jm == im && return true
(id//3 == jd//3) &&
(jm//3 == im//3)
}
func solve(grid) {
for i in ^grid {
grid[i] && next
var t = [grid[{|j| check(i, j) }.grep(^grid)]].f... |
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... | #Sidef | Sidef | say "knight".substr(1); # strip first character
say "socks".substr(0, -1); # strip last character
say "brooms".substr(1, -1); # strip both first and last characters
say "与今令".substr(1, -1); # => 今 |
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.
| #Raven | Raven | 0 [ 1 2 3 ] each +
1 [ 1 2 3 ] each * |
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.
| #REBOL | REBOL | rebol [
Title: "Sum and Product"
URL: http://rosettacode.org/wiki/Sum_and_product_of_array
]
; Simple:
sum: func [a [block!] /local x] [x: 0 forall a [x: x + a/1] x]
product: func [a [block!] /local x] [x: 1 forall a [x: x * a/1] x]
; Way too fancy:
redux: func [
"Applies an operation across an a... |
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... | #NewLISP | NewLISP | (let (s 0)
(for (i 1 1000)
(inc s (div 1 (* i i))))
(println 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 |... | #Wren | Wren | var s = "little"
var t = "Mary had a %(s) lamb"
System.print(t) |
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 |... | #Vlang | Vlang |
txt := "little"
str := "Mary had a $txt lamb"
println(str)
|
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 |... | #XPL0 | XPL0 | char X;
[X:= "little";
Text(0, "Mary had a "); Text(0, X); Text(0, " 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... | #ScriptBasic | ScriptBasic |
str1 = "She was a soul stripper. She took my heart!"
rmv = "aei"
FOR i = 1 TO LEN(rmv)
str1 = REPLACE(str1, MID(rmv, i, 1), "")
NEXT
PRINT str1,"\n"
|
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... | #Sed | Sed | #!/bin/bash
strip_char()
{
echo "$1" | sed "s/[$2]//g"
} |
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 |... | #Rust | Rust | use std::ascii::AsciiExt; // for case insensitives only
fn main() {
// only same types can be compared
// String and String or &str and &str
// exception: strict equality and inequality also work on &str and String
let a: &str = "abc";
let b: String = "Bac".to_owned();
// Strings are coerced... |
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 |... | #Scala | Scala | object Compare extends App {
def compare(a: String, b: String) {
if (a == b) println(s"'$a' and '$b' are lexically equal.")
else println(s"'$a' and '$b' are not lexically equal.")
if (a.equalsIgnoreCase(b)) println(s"'$a' and '$b' are case-insensitive lexically equal.")
else println(s"'$a' and '$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... | #min | min | "alphaBETA" uppercase
"alphaBETA" lowercase
"alphaBETA" capitalize |
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... | #MiniScript | MiniScript | mixedString = "alphaBETA"
print "Upper Case of " + mixedString + " is " + mixedString.upper
print "Lower Case of " + mixedString + " is " + mixedString.lower |
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 |... | #Lingo | Lingo | a = "Hello world!"
b = "Hello"
-- Determining if the first string starts with second string
put a starts b
-- 1
-- Determining if the first string contains the second string at any location
put a contains b
-- 1
-- Determining if the first string ends with the second string
put a.char[a.length-b.length+1..a.lengt... |
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... | #Kotlin | Kotlin | // version 1.0.6
fun main(args: Array<String>) {
val s = "José"
println("The char length is ${s.length}")
println("The byte length is ${Character.BYTES * s.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... | #PHL | PHL | module stringcat;
extern printf;
@Integer main [
var a = "hello";
var b = a + " literal";
printf("%s\n", b);
return 0;
] |
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... | #PHP | PHP | <?php
$s = "hello";
echo $s . " literal" . "\n";
$s1 = $s . " literal";
echo $s1 . "\n";
?> |
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.
| #Rust | Rust |
extern crate rug;
use rug::Integer;
use rug::ops::Pow;
fn main() {
for i in [3, 20, 100, 1_000].iter() {
let ten = Integer::from(10);
let mut limit = Integer::from(Integer::from(&ten.pow(*i as u32)) - 1);
let mut aux_3_1 = &limit.mod_u(3u32);
let mut aux_3_2 = Integer::from(&li... |
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
| #Stata | Stata | function sumdigits(s) {
a = ascii(strupper(s)):-48
return(sum(a:-(a:>9)*7))
}
sumdigits("1")
1
sumdigits("1234")
10
sumdigits("fe")
29
sumdigits("f0e")
29
sumdigits(inbase(16, 254, 10))
29 |
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
| #Unix_shell | Unix shell | $ cat toto
1
2
4
8
16
$ cat toto toto | paste -sd*
1*2*4*8*16*1*2*4*8*16
$ cat toto toto | paste -sd* | bc -l
1048576
|
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
| #Ursala | Ursala | #import nat
ssq = sum:-0+ product*iip
#cast %n
main = ssq <21,12,77,0,94,23,96,93,72,72,79,24,8,50,9,93> |
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... | #VBScript | VBScript |
Function LeftTrim(s)
Set regex = New RegExp
With regex
.Pattern = "^\s*"
If .Test(s) Then
LeftTrim = .Replace(s,"")
Else
LeftTrim = s
End If
End With
End Function
Function RightTrim(s)
Set regex = New RegExp
With regex
.Pattern = "\s*$"
If .Test(s) Then
RightTrim = .Replace(s,"")
Else
... |
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... | #Wren | Wren | var a = " \t\r\nString with leading whitespace removed"
var b = "String with trailing whitespace removed \t\r\n"
var c = " \t\r\nString with both leading and trailing whitespace removed \t\r\n"
var d = " \t\r\n\f\vString with leading whitespace, form feed and verical tab characters removed"
System.print("'%(a.trim... |
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 |... | #MUMPS | MUMPS |
SUBSTR(S,N,M,C,K)
;show substring operations
;S is the string
;N is a position within the string (that is, n<length(string))
;M is an integer of positions to show
;C is a character within the string S
;K is a substring within the string S
;$Find returns the position after the substring
NEW X
WRITE !,"The bas... |
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 |... | #Nanoquery | Nanoquery | str = "test string"
println substr(str, m, m + n)
println substr(str, n, len(str))
println substr(str, 0, len(str) - 1)
println substr(str, str.indexOf("s"), str.indexOf("s") + m)
println substr(str, str.indexOf("str"), str.indexOf("str") + m) |
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.
| #Shale | Shale |
#!/usr/local/bin/shale
time library
// This solves a sudoku with:
// row/column/3x3box constraints (standard sudoku)
// row/column/irregular, or jigsaw, region constraints
// optionally with a Chess Knight's move constraint.
// It is based on the python code from the Computerphile video
// https://www.youtube.... |
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... | #Smalltalk | Smalltalk |
s := 'upraisers'.
Transcript show: 'Top: ', s allButLast; nl.
Transcript show: 'Tail: ', s allButFirst; nl.
Transcript show: 'Without both: ', s allButFirst allButLast; nl.
Transcript show: 'Without both using substring method: ', (s copyFrom: 2 to: s size - 1); nl.
|
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.
| #Red | Red | Red [
red-version: 0.6.4
description: "Find the sum and product of an array of numbers."
]
product: function [
"Returns the product of all values in a block."
values [any-list! vector!]
][
result: 1
foreach value values [result: result * value]
result
]
a: [1 2 3 4 5 6 7 8 9 10]
print a
... |
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... | #Nial | Nial | |sum (1 / power (count 1000) 2)
=1.64393 |
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 |... | #zkl | zkl | "Mary had a X lamb.".replace("X","big") |
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... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const func string: stripchars (in string: mainStri, in string: charList) is func
result
var string: strippedStri is "";
local
var char: ch is ' ';
begin
strippedStri := mainStri;
for ch range charList do
strippedStri := replace(strippedStri, str(ch), "");
end ... |
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... | #Sidef | Sidef | func stripchars(str, char_list) {
str.tr(char_list, "", "d");
} |
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 |... | #Scheme | Scheme |
;; Comparing two strings for exact equality
(string=? "hello" "hello")
;; Comparing two strings for inequality
(not (string=? "hello" "Hello"))
;; Checking if the first string is lexically ordered before the second
(string<? "bar" "foo")
;; Checking if the first string is lexically ordered after the second
(st... |
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... | #mIRC_Scripting_Language | mIRC Scripting Language | echo -ag $upper(alphaBETA)
echo -ag $lower(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... | #Modula-3 | Modula-3 | MODULE TextCase EXPORTS Main;
IMPORT IO, Text, ASCII;
PROCEDURE Upper(txt: TEXT): TEXT =
VAR
len := Text.Length(txt);
res := "";
BEGIN
FOR i := 0 TO len - 1 DO
res := Text.Cat(res, Text.FromChar(ASCII.Upper[Text.GetChar(txt, i)]));
END;
RETURN res;
END Upper;
PROCEDURE Lower(txt: T... |
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 |... | #Logo | Logo | to starts.with? :sub :thing
if empty? :sub [output "true]
if empty? :thing [output "false]
if not equal? first :sub first :thing [output "false]
output starts.with? butfirst :sub butfirst :thing
end
to ends.with? :sub :thing
if empty? :sub [output "true]
if empty? :thing [output "false]
if not equal? la... |
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 |... | #Lua | Lua | s1 = "string"
s2 = "str"
s3 = "ing"
s4 = "xyz"
print( "s1 starts with s2: ", string.find( s1, s2 ) == 1 )
print( "s1 starts with s3: ", string.find( s1, s3 ) == 1, "\n" )
print( "s1 contains s3: ", string.find( s1, s3 ) ~= nil )
print( "s1 contains s3: ", string.find( s1, s4 ) ~= nil, "\n" )
print( "s1 ends wi... |
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... | #LabVIEW | LabVIEW |
{script
LAMBDATALK.DICT["W.unicodeLength"] = function() {
function countCodePoints(str) {
var point,
index,
width = 0,
len = 0;
for (index = 0; index < str.length;) {
point = str.codePointAt(index);
width = 0;
while (point) {
width += 1;
point =... |
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... | #Picat | Picat | main =>
Hello = "Hello, ",
print(Hello ++ "world!" ++ "\n"),
String = Hello ++ "world!",
String := String ++ "\n",
print(String). |
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... | #PicoLisp | PicoLisp | (let Str1 "First text"
(prinl Str1 " literal")
(let Str2 (pack Str1 " literal")
(prinl Str2) ) ) |
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.
| #Scala | Scala | def sum35( max:BigInt ) : BigInt = max match {
// Simplest solution but limited to Ints only
case j if j < 100000 => (1 until j.toInt).filter( i => i % 3 == 0 || i % 5 == 0 ).sum
// Using a custom iterator that takes Longs
case j if j < 10e9.toLong => {
def stepBy( step:Long ) : Iterator[Long] = new Ite... |
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
| #Swift | Swift |
extension String: Error {
func sumDigits(withBase base: Int) throws -> Int {
func characterToInt(_ base: Int) -> (Character) -> Int? {
return { char in
return Int(String(char), radix: base)
}
}
return try self.map(characterToInt(base))
... |
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
| #V | V | [sumsq [dup *] map 0 [+] fold].
[] sumsq
=0
[1 2 3] sumsq |
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
| #VBA | VBA | Public Sub sum_of_squares()
Debug.Print WorksheetFunction.SumSq([{1,2,3,4,5,6,7,8,9,10}])
End Sub |
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... | #XPL0 | XPL0 | code ChOut=8, CrLf=9, Text=12;
string 0; \use zero-terminated string convention
func StripLead(S0); \Strip leading whitespace (<=$20) from string
char S0;
char S1(80); \BEWARE: very temporary string space returned
int I, J, C, Stripped;
[I:= 0; J:= 0; Stripped:=... |
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... | #Yabasic | Yabasic | s$ = "\t test \n"
print "--",ltrim$(s$),"--"
print "--",rtrim$(s$),"--"
print "--",trim$(s$),"--" |
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 |... | #Nemerle | Nemerle | using System;
using System.Console;
module Substrings
{
Main() : void
{
string s = "0123456789";
def n = 3;
def m = 2;
def c = '3';
def z = "345";
WriteLine(s.Substring(n, m));
WriteLine(s.Substring(n, s.Length - n));
WriteLine(s.Substring(0, 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.
| #SQL | SQL | WITH
symbols (d) AS (SELECT to_char(level) FROM dual CONNECT BY level <= 9)
, board (i) AS (SELECT level FROM dual CONNECT BY level <= 81)
, neighbors (i, j) AS (
SELECT b1.i, b2.i
FROM board b1 INNER JOIN board b2
ON b1.i != b2.i
AND (
MOD(b1.i - b2.i, 9) ... |
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... | #SNOBOL4 | SNOBOL4 | "knight" len(1) rem . output ;* strip first character
"socks" rtab(1) . output ;* strip last character
"brooms" len(1) rtab(1) . output ;* strip both first and last characters |
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... | #Standard_ML | Standard ML | - val str = "abcde";
val str = "abcde" : string
- String.substring(str, 1, String.size str - 1);
val it = "bcde" : string
- String.substring(str, 0, String.size str - 1);
val it = "abcd" : string
- String.substring(str, 1, String.size str - 2);
val it = "bcd" : string |
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.
| #REXX | REXX | /*REXX program adds and multiplies N elements of a (populated) array @. */
numeric digits 200 /*200 decimal digit #s (default is 9).*/
parse arg N .; if N=='' then N=20 /*Not specified? Then use the default.*/
do j=1 for N /*build array of N elements (or 20... |
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... | #Nim | Nim | var s = 0.0
for n in 1..1000: s += 1 / (n * n)
echo s |
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... | #Smalltalk | Smalltalk | | stripChars |
stripChars := [ :string :chars |
string reject: [ :c | chars includes: c ] ].
stripChars
value: 'She was a soul stripper. She took my heart!'
value: 'aei'.
"'Sh ws soul strppr. Sh took my hrt!'" |
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... | #SNOBOL4 | SNOBOL4 | DEFINE("strip(strip,c)") :(strip_end)
strip strip ANY(c) = :S(strip)F(RETURN)
strip_end
chars = HOST(2, HOST(3)) ;* Get command line argument
chars = IDENT(chars) "aei"
again line = INPUT :F(END)
OUTPUT = strip(line, chars) :(again)
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 |... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: showComparisons (in string: a, in string: b) is func
begin
writeln("compare " <& literal(a) <& " with " <& literal(b) <&":");
writeln("a = b returns: " <& a = b);
writeln("a <> b returns: " <& a <> b);
writeln("a < b returns: " <& a < b);
writeln("a > b r... |
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 |... | #Sidef | Sidef | var methods = %w(== != > >= < <= <=>)
for s1, s2 in [<YUP YUP>,<YUP Yup>,<bot bat>,<aaa zz>] {
methods.each{|m| "%s %s %s\t%s\n".printf(s1, m, s2, s1.(m)(s2))}
print "\n"
} |
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... | #MUMPS | MUMPS |
STRCASE(S)
SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
SET LO="abcdefghijklmnopqrstuvwxyz"
WRITE !,"Given: "_S
WRITE !,"Upper: "_$TRANSLATE(S,LO,UP)
WRITE !,"Lower: "_$TRANSLATE(S,UP,LO)
QUIT
|
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... | #Nanoquery | Nanoquery | string = "alphaBETA"
println upper(string)
println lower(string) |
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 |... | #M2000_Interpreter | M2000 Interpreter |
Module StringMatch {
A$="Hello World"
Print A$ ~ "Hello*"
Print A$ ~ "*llo*"
p=Instr(A$, "llo")
Print p=3
\\ Handle multiple occurance for "o"
p=Instr(A$, "o")
While p > 0 {
Print "position:";p;{ for "o"}
p=Instr(A$, "o", p+1)
}
Print... |
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... | #Lambdatalk | Lambdatalk |
{script
LAMBDATALK.DICT["W.unicodeLength"] = function() {
function countCodePoints(str) {
var point,
index,
width = 0,
len = 0;
for (index = 0; index < str.length;) {
point = str.codePointAt(index);
width = 0;
while (point) {
width += 1;
point =... |
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... | #Pike | Pike |
string hello = "hello ";
write(hello + "world" + "\n");
string all_of_it = hello + "world";
write(all_of_it + "\n");
|
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... | #PL.2FI | PL/I | declare (s, t) character (30) varying;
s = 'hello from me';
display (s || ' to you.' );
t = s || ' to you all';
display (t); |
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.
| #Scheme | Scheme | (fold (lambda (x tot) (+ tot (if (or (zero? (remainder x 3)) (zero? (remainder x 5))) x 0))) 0 (iota 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
| #Tcl | Tcl | proc sumDigits {num {base 10}} {
set total 0
foreach d [split $num ""] {
if {[string is alpha $d]} {
set d [expr {[scan [string tolower $d] %c] - 87}]
} elseif {![string is digit $d]} {
error "bad digit: $d"
}
if {$d >= $base} {
error "bad digit: $d"
}
incr total $d
}
return $total
... |
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
| #VBScript | VBScript |
Function sum_of_squares(arr)
If UBound(arr) = -1 Then
sum_of_squares = 0
End If
For i = 0 To UBound(arr)
sum_of_squares = sum_of_squares + (arr(i)^2)
Next
End Function
WScript.StdOut.WriteLine sum_of_squares(Array(1,2,3,4,5))
WScript.StdOut.WriteLine sum_of_squares(Array())
|
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
| #Visual_Basic_.NET | Visual Basic .NET |
Private Shared Function sumsq(ByVal i As ICollection(Of Integer)) As Integer
If i Is Nothing OrElse i.Count = 0 Then
Return 0
End If
Return i.[Select](Function(x) x * x).Sum()
End Function
Private Shared Sub Main()
Dim a As Integer() = New Integer() {1, 2, 3, 4, 5}
... |
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... | #zkl | zkl | "\t\n hoho\n\t\ ".strip() //-->"hoho" |
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... | #Zoea | Zoea |
program: trim_left
input: ' abcd'
output: 'abcd'
program: trim_right
input: 'abcd '
output: 'abcd'
program: trim
input: ' abcd '
output: 'abcd'
|
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 |... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols
s = 'abcdefghijk'
n = 4
m = 3
say s
say s.substr(n, m)
say s.substr(n)
say s.substr(1, s.length - 1)
say s.substr(s.pos('def'), m)
say s.substr(s.pos('g'), m)
return
|
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.
| #Stata | Stata | mata
function sudoku(a) {
s = J(81,20,.)
t = J(81,3,.)
v = J(81,9,1)
w = J(81,1,0)
for (i=1; i<=9; i++) {
for (j=1; j<=9; j++) {
n = (i-1)*9+j
k = floor((i-1)/3)*3+floor((j-1)/3)+1
t[n,.] = i,j,k
}
}
for (i=1; i<=81; i++) {
for (j=i+1; j<=81; j++) {
if (any(t[i,.]:==t[j,.])) {
w[i]=w[i]+1
... |
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... | #Swift | Swift | let txt = "0123456789"
println(dropFirst(txt))
println(dropLast(txt))
println(dropFirst(dropLast(txt))) |
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... | #Tcl | Tcl | puts [string range "knight" 1 end]; # strip first character
puts [string range "write" 0 end-1]; # strip last character
puts [string range "brooms" 1 end-1]; # 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.
| #Ring | Ring |
aList = 1:10 nSum=0 nProduct=0
for x in aList nSum += x nProduct *= x next
See "Sum = " + nSum + nl
See "Product = " + nProduct + nl
|
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... | #Objeck | Objeck |
bundle Default {
class SumSeries {
function : Main(args : String[]) ~ Nil {
DoSumSeries();
}
function : native : DoSumSeries() ~ Nil {
start := 1;
end := 1000;
sum := 0.0;
for(x : Float := start; x <= end; x += 1;) {
sum += f(x);
};
IO.Console->G... |
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... | #Standard_ML | Standard ML | fun stripchars (string, chars) = let
fun aux c =
if String.isSubstring (str c) chars then
""
else
str c
in
String.translate aux string
end |
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... | #Swift | Swift | extension String {
func stripCharactersInSet(chars: [Character]) -> String {
return String(seq: filter(self) {find(chars, $0) == nil})
}
}
let aString = "She was a soul stripper. She took my heart!"
let chars: [Character] = ["a", "e", "i"]
println(aString.stripCharactersInSet(chars)) |
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 |... | #Smalltalk | Smalltalk | methods := #(= ~= > >= < <= sameAs: ).
#(
('YUP' 'YUP')
('YUP' 'yup')
) pairsDo:[:s1 :s2 |
methods do:[:m |
'%-20s\t%s\n' printf:
{
('(%S %s %S)' printf:{s1 . m . s2}) .
(s1 perform:m with:s2)
} on:Stdout
].
Stdout cr
] |
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... | #Nemerle | Nemerle | using System.Console;
using System.Globalization;
module StringCase
{
Main() : void
{
def alpha = "alphaBETA";
WriteLine(alpha.ToUpper());
WriteLine(alpha.ToLower());
WriteLine(CultureInfo.CurrentCulture.TextInfo.ToTitleCase("exAmpLe sTrinG"));
}
} |
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... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols
abc = 'alphaBETA'
say abc.upper
say abc.lower
say abc.upper(1, 1) -- capitalize 1st character
|
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 |... | #Maple | Maple |
> with( StringTools ): # bind package exports at the top-level
> s := "dzrIemaWWIMidXYZwGiqkOOn":
> s[1..4]; # pick a prefix
"dzrI"
> IsPrefix( s[ 1 .. 4 ], s ); # check it
true
> s[ -4 .. -1 ]; # pick a suffix
"kO... |
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 |... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | StartWith[x_, y_] := MemberQ[Flatten[StringPosition[x, y]], 1]
EndWith[x_, y_] := MemberQ[Flatten[StringPosition[x, y]], StringLength[x]]
StartWith["XYZaaabXYZaaaaXYZXYZ", "XYZ"]
EndWith["XYZaaabXYZaaaaXYZXYZ", "XYZ"]
StringPosition["XYZaaabXYZaaaaXYZXYZ", "XYZ"] |
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... | #Lasso | Lasso | 'Hello, world!'->size // 13
'møøse'->size // 5
'𝔘𝔫𝔦𝔠𝔬𝔡𝔢'->size // 7 |
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... | #LFE | LFE |
(length "ASCII text")
10
(length "𝔘𝔫𝔦𝔠𝔬𝔡𝔢 𝔗𝔢𝒙𝔱")
12
> (set encoded (binary ("𝔘𝔫𝔦𝔠𝔬𝔡𝔢 𝔗𝔢𝒙𝔱" utf8)))
#B(240 157 148 152 240 157 148 171 240 157 ...)
> (length (unicode:characters_to_list encoded 'utf8))
12
|
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... | #Plain_English | Plain English | To run:
Start up.
Put "hello" into a string.
Put the string then " world" into another string.
Write the string to the console.
Write the other string to the console.
Wait for the escape key.
Shut down. |
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... | #PowerShell | PowerShell | $s = "Hello"
Write-Host $s World.
# alternative, using variable expansion in strings
Write-Host "$s World."
$s2 = $s + " World."
Write-Host $s2 |
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... | #PureBasic | PureBasic | If OpenConsole()
s$ = "hello"
PrintN( s$ + " literal")
s2$ = s$ + " literal"
PrintN(s2$)
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf |
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.
| #Seed7 | Seed7 | $ include "seed7_05.s7i";
include "bigint.s7i";
const func bigInteger: sum35 (in bigInteger: n) is func
result
var bigInteger: sum35 is 0_;
local
const func bigInteger: sumMul (in bigInteger: n, in bigInteger: f) is func
result
var bigInteger: sumMul is 0_;
local
var bigInteg... |
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.
| #Sidef | Sidef | func sumMul(n, f) {
var m = int((n - 1) / f)
f * m * (m + 1) / 2
}
func sum35(n) {
sumMul(n, 3) + sumMul(n, 5) - sumMul(n, 15)
}
for i in (1..20) {
printf("%2s:%22s %s\n", i, 10**i, sum35(10**i))
} |
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
| #TI-83_BASIC | TI-83 BASIC | "01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"→Str1
Disp "SUM DIGITS OF INT"
Disp "-----------------"
Disp "ENTER NUMBER"
Input Str2
Disp "ENTER BASE"
Input B
0→R
length(Str2)→L
For(I,1,L,1)
sub(Str2,I,1)→Str3
inString(Str1,Str3)-1→S
If S≥B or S=-1:Then
Disp "ERROR:"
Disp Str3
Disp "NOT IN BASE"
Disp B
Stop
End
R+S→R
End
Disp... |
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
| #Wortel | Wortel | @sum !*^@sq [3 1 4 1 5 9] ; returns 133 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.