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_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 |... | #Ruby | Ruby | irb(main):001:0> extra = 'little'
=> "little"
irb(main):002:0> "Mary had a #{extra} lamb."
=> "Mary had a little lamb."
irb(main):003:0> "Mary had a %s lamb." % extra
=> "Mary had a little 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... | #PureBasic | PureBasic | Procedure.s stripChars(source.s, charsToStrip.s)
Protected i, *ptrChar.Character, length = Len(source), result.s
*ptrChar = @source
For i = 1 To length
If Not FindString(charsToStrip, Chr(*ptrChar\c))
result + Chr(*ptrChar\c)
EndIf
*ptrChar + SizeOf(Character)
Next
ProcedureReturn result
E... |
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 |... | #PureBasic | PureBasic | Macro StrTest(Check,tof)
Print("Test "+Check+#TAB$)
If tof=1 : PrintN("true") : Else : PrintN("false") : EndIf
EndMacro
Procedure.b StrBool_eq(a$,b$) : ProcedureReturn Bool(a$=b$) : EndProcedure
Procedure.b StrBool_n_eq(a$,b$) : ProcedureReturn Bool(a$<>b$) : EndProcedure
Proced... |
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... | #Julia | Julia | julia> uppercase("alphaBETA")
"ALPHABETA"
julia> lowercase("alphaBETA")
"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... | #K | K |
s:"alphaBETA"
upper:{i:_ic x; :[96<i; _ci i-32;_ci i]}'
lower:{i:_ic x; :[91>i; _ci i+32;_ci i]}'
upper s
"ALPHABETA"
lower s
"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 |... | #jq | jq | # startswith/1 is boolean:
"abc" | startswith("ab")
#=> true |
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... | #HicEst | HicEst | LEN("1 character == 1 byte") ! 21 |
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... | #MUMPS | MUMPS | STRCAT
SET S="STRING"
WRITE !,S
SET T=S_" LITERAL"
WRITE !,T
QUIT |
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... | #Nanoquery | Nanoquery | s1 = "hello"
println s1 + " world"
s2 = s1 + " world"
println s2 |
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.
| #Q | Q | s35:{sum {?[(0=x mod 3) | 0=x mod 5;x;0]} each 1+til x - 1}
s35 each 10 100 1000 10000 1000000 |
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
| #Ring | Ring |
see "sum digits of 1 = " + sumDigits(1) + nl
see "sum digits of 1234 = " + sumDigits(1234) + nl
func sumDigits n
sum = 0
while n > 0.5
m = floor(n / 10)
digit = n - m * 10
sum = sum + digit
n = m
end
return 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
| #Scala | Scala | def sum_of_squares(xs: Seq[Double]) = xs.foldLeft(0) {(a,x) => a + x*x} |
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... | #Run_BASIC | Run BASIC | string$ = " abcdefg "
print " Top:";trim$(string$+"|") ' top left trim
print "Bottom:";trim$("|"+string$) ' bottom right trim
print " Both:";trim$(string$) ' both left and right
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... | #Rust | Rust | fn main() {
let spaces = " \t\n\x0B\x0C\r \u{A0} \u{2000}\u{3000}";
let string_with_spaces = spaces.to_owned() + "String without spaces" + spaces;
assert_eq!(string_with_spaces.trim(), "String without spaces");
assert_eq!(string_with_spaces.trim_left(), "String without spaces".to_owned() + 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 |... | #Liberty_BASIC | Liberty BASIC | 'These tasks can be completed with various combinations of Liberty Basic's
'built in Mid$()/ Instr()/ Left$()/ Right$()/ and Len() functions, but these
'examples only use the Mid$()/ Instr()/ and Len() functions.
baseString$ = "Thequickbrownfoxjumpsoverthelazydog."
n = 12
m = 5
'starting from n characters in and of... |
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.
| #Rascal | Rascal | import Prelude;
import vis::Figure;
import vis::Render;
public rel[int,int,int] sudoku(rel[int x, int y, int v] sudoku){
annotated= annotateGrid(sudoku);
solved = {<0,0,0,0,{0}>};
while(!isEmpty(solved)){
for (n <- [0 ..8]){
column = domainR(annotated, {n});
annotated -= column;
annotated += reduceOpt... |
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... | #Racket | Racket |
#lang racket
(define str "ストリング")
(substring str 1)
(substring str 0 (sub1 (string-length str)))
(substring str 1 (sub1 (string-length str)))
|
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.
| #Plain_English | Plain English | An element is a thing with a number.
To find a sum and a product of some elements:
Put 0 into the sum.
Put 1 into the product.
Get an element from the elements.
Loop.
If the element is nil, exit.
Add the element's number to the sum.
Multiply the product by the element's number.
Put the element's next into the element... |
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... | #Maxima | Maxima | (%i45) sum(1/x^2, x, 1, 1000);
835459384831496894781878542648[806 digits]396236858699094240207812766449
(%o45) ------------------------------------------------------------------------
508207201043258126178352922730[806 digits]886537101453118476390400000000
(%i46) sum(1/x^2, x, 1, 1000),numer;
(%o46) 1.6... |
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 |... | #Run_BASIC | Run BASIC | "a$ = Mary had a X lamb."
a$ = word$(a$,1,"X")+"little"+word$(a$,2,"X")
print a$
|
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 |... | #Rust | Rust | fn main() {
println!("Mary had a {} lamb", "little");
// You can specify order
println!("{1} had a {0} lamb", "little", "Mary");
// Or named arguments if you prefer
println!("{name} had a {adj} lamb", adj="little", name="Mary");
} |
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... | #Python | Python | >>> def stripchars(s, chars):
... return s.translate(None, chars)
...
>>> 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 |... | #Python | Python | def compare(a, b):
print("\n%r is of type %r and %r is of type %r"
% (a, type(a), b, type(b)))
if a < b: print('%r is strictly less than %r' % (a, b))
if a <= b: print('%r is less than or equal to %r' % (a, b))
if a > b: print('%r is strictly greater than %r' % (a, b))
i... |
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... | #Kotlin | Kotlin | // version 1.0.6
fun main(args: Array<String>) {
val s = "alphaBETA"
println(s.toUpperCase())
println(s.toLowerCase())
println(s.capitalize())
println(s.decapitalize())
} |
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 |... | #Julia | Julia |
startswith("abcd","ab") #returns true
findfirst("ab", "abcd") #returns 1:2, indices range where string was found
endswith("abcd","zn") #returns false
match(r"ab","abcd") != Nothing #returns true where 1st arg is regex string
for r in eachmatch(r"ab","abab")
println(r.offset)
en... |
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... | #HolyC | HolyC | U8 *string = "Hello, world!";
Print("%d\n", StrLen(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... | #Neko | Neko | /**
String concatenation, in Neko
Tectonics:
nekoc string-concatenation.neko
neko string-concatenation [addon]
*/
var arg = $loader.args[0]
var addon
if arg != null addon = $string(arg)
var s = "abc"
$print("s: ", s, "\n")
var c = s + "def"
$print("c: ", c, "\n")
if arg != null {
c += addon
$p... |
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.
| #Quackery | Quackery | [ dup 1+ * 2 / ] is triangulared ( n --> n )
[ 1 -
dup 3 / triangulared 3 *
over 5 / triangulared 5 * +
swap 15 / triangulared 15 * - ] is sum-of-3s&5s ( n --> n )
1000 sum-of-3s&5s echo cr
10 20 ** sum-of-3s&5s echo cr |
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
| #Ruby | Ruby | def sum_digits(num, base = 10) = num.digits(base).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
| #Scheme | Scheme | (define (sum-of-squares l)
(apply + (map * l l))) |
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
| #Seed7 | Seed7 | $ include "seed7_05.s7i";
include "float.s7i";
const array float: list1 is [] (3.0, 1.0, 4.0, 1.0, 5.0, 9.0);
const array float: list2 is 0 times 0.0;
const func float: squaredSum (in array float: floatList) is func
result
var float: sum is 0.0;
local
var float: number is 0.0;
begin
for number r... |
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... | #Sather | Sather | class MAIN is
ltrim(s :STR) :STR is
i ::= 0;
loop while!(i < s.size);
if " \t\f\v\n".contains(s[i]) then
i := i + 1;
else
break!;
end;
end;
return s.tail(s.size - i);
end;
rtrim(s :STR) :STR is
i ::= s.size-1;
loop while!(i ... |
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... | #Scala | Scala | def trimLeft(str: String) = str dropWhile(_.isWhitespace)
def trimRight(str: String) = str take (str.lastIndexWhere(!_.isWhitespace) + 1)
def trimRight2(str: String) = trimLeft(str reverse) reverse
def trim(str: String) = str trim
def testTrim() = {
val str = " \u001F String with spaces \t \n \r "
print... |
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 |... | #Lingo | Lingo | str = "The quick brown fox jumps over the lazy dog"
-- starting from n characters in and of m length
n = 5
m = 11
put str.char[n..n+m-1]
-- "quick brown"
-- starting from n characters in, up to the end of the string
n = 11
put str.char[n..str.length]
-- "brown fox jumps over the lazy dog"
-- whole string minus la... |
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.
| #REXX | REXX | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Register And Flag Usage
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 0 General purpose variable used for miscelaneous purposes
; 1 Current index (0-80) in the ps... |
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... | #Raku | Raku | my $s = '𝄪♯♮♭𝄫';
print qq:to/END/;
Original:
$s
Remove first character:
{ substr($s, 1) }
{ $s.substr(1) }
Remove last character:
{ substr($s, 0, *-1) }
{ $s.substr( 0, *-1) }
{ $s.chop }
Remove first and last characters:
{ substr($s, 1, *-1) }
{ $s.substr(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.
| #Pop11 | Pop11 | lvars i, sum = 0, prod = 1, ar = {1 2 3 4 5 6 7 8 9};
for i from 1 to length(ar) do
ar(i) + sum -> sum;
ar(i) * prod -> prod;
endfor; |
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.
| #PostScript | PostScript |
/sumandproduct
{
/x exch def
/sum 0 def
/prod 0 def
/i 0 def
x length 0 eq
{
}
{
/prod prod 1 add def
x length{
/sum sum x i get add def
/prod prod x i get mul def
/i i 1 add def
}repeat
}ifelse
sum ==
prod ==
}def
|
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... | #MAXScript | MAXScript | total = 0
for i in 1 to 1000 do
(
total += 1.0 / pow i 2
)
print total |
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... | #min | min | 0 1 (
((dup * 1 swap /) (id)) cleave
((+) (succ)) spread
) 1000 times pop print |
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 |... | #Scala | Scala | object StringInterpolation extends App {
import util.matching.Regex._
val size = "little"
{ // Method I (preferred)
// Scala 2.10.0 supports direct string interpolation
// by putting "s" at the beginning of the string.
println("V2.10+ : " + s"Mary had a $size lamb,")
}
{ // Method II
//... |
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... | #Quackery | Quackery | [ $ "" swap witheach [ upper join ] ] is upper$ ( $ --> $ )
[ $ "" swap witheach [ lower join ] ] is lower$ ( $ --> $ )
[ 0 swap witheach [ bit | ] ] is ->set ( [ --> s )
[ bit & not ] is !in ( s c --> b )
[ $ "" unrot
upper$ dup lower$ join ( omit this li... |
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... | #Racket | Racket |
#lang racket
;; Using list operations
(define (stripchars1 text chars)
(list->string (remove* (string->list chars) (string->list text))))
;; Using a regexp
;; => will be broken if chars have "-" or "]" or "\\"
(define (stripchars2 text chars)
(regexp-replace* (~a "[" chars "]+") text ""))
|
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 |... | #QB64 | QB64 |
Dim As String String1, String2
' direct string comparison using case sensitive
String1 = "GWbasic"
String2 = "QuickBasic"
If String1 = String2 Then Print String1; " is equal to "; String2 Else Print String1; " is NOT egual to "; String2
String1 = "gWbasic"
String2 = "GWBasic"
If String1 = String2 Then Print Stri... |
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 |... | #Quackery | Quackery | /O> ( compare two strings for equality )
... $ "abc" $ "xyz" =
... echo ( 0 = false, 1 = true )
...
0
Stack empty.
/O> ( compare two strings for inequality )
... $ "abc" $ "xyz" !=
... echo ( 0 = false, 1 = true )
...
1
Stack empty.
//O> ( compare two strings to see if one is lexically ordered before the other )
..... |
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... | #Lambdatalk | Lambdatalk |
{span {@ style="text-transform:lowercase"} alphaBETA } -> alphabeta
{span {@ style="text-transform:uppercase"} alphaBETA } -> 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... | #Lasso | Lasso | // Direct string return
'alphaBETA'->uppercase&
'alphaBETA'->lowercase&
// Assignment and manipulation of variables
local(toupper = 'alphaBETA')
#toupper->uppercase
#toupper
local(tolower = 'alphaBETA')
#tolower->lowercase
#tolower |
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 |... | #K | K | startswith: {:[0<#p:_ss[x;y];~*p;0]}
endswith: {0=(-#y)+(#x)-*_ss[x;y]}
contains: {0<#_ss[x;y]} |
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... | #Icon_and_Unicon | Icon and Unicon | length := *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... | #Nemerle | Nemerle | using System;
using System.Console;
using Nemerle.Utility.NString; // contains method Concat()
module Stringcat
{
Main() : void
{
def text1 = "This string has";
def cat1 = Concat( " ", [text, "been concatenated"]);
def cat2 = text1 + " also been concatenated";
Write($"$cat1\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... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref savelog symbols
s1 = 'any text value'
s2 = 'another string literal'
s3 = s1 s2 -- concatenate variables with blank space (note that only one blank space is added)
s4 = s1 || s2 -- concatenate variables with abuttal (here, no blank spaces are added)
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.
| #R | R | m35 = function(n) sum(unique(c(
seq(3, n-1, by = 3), seq(5, n-1, by = 5))))
m35(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
| #Rust | Rust | struct DigitIter(usize, usize);
impl Iterator for DigitIter {
type Item = usize;
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 0 {
None
} else {
let ret = self.0 % self.1;
self.0 /= self.1;
Some(ret)
}
}
}
fn main() {
... |
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
| #Sidef | Sidef | func sum_of_squares(vector) {
var sum = 0;
vector.each { |n| sum += n**2 };
return sum;
}
say sum_of_squares([]); # 0
say sum_of_squares([1,2,3]); # 14 |
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
| #Slate | Slate | {1. 2. 3} reduce: [|:x :y| y squared + x].
{} reduce: [|:x :y| y squared + x] ifEmpty: [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... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: main is func
local
const string: testStri is " \t \r \n String with spaces \t \r \n ";
begin
writeln(ltrim(testStri));
writeln(rtrim(testStri));
writeln(trim(testStri));
end func; |
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... | #Sidef | Sidef | var s = " \t\v\r\n\ffoo bar \t\v\r\n\f";
say s.strip_beg.dump; # remove leading whitespaces
say s.strip_end.dump; # remove trailing whitespaces
say s.strip.dump; # remove both leading and trailing whitespace |
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 |... | #LiveCode | LiveCode | put "pple" into x
answer char 2 to char 5 of x // n = 2, m=5
answer char 2 to len(x) of x // n = 2, m = len(x), can also use -1
answer char 1 to -2 of x // n = 1, m = 1 less than length of string
answer char offset("p",x) to -1 of x // known char "p" to end of string
answer char offset("pl",x) to -1 of x // known "... |
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 |... | #Logo | Logo | to items :n :thing
if :n >= count :thing [output :thing]
output items :n butlast :thing
end
to butitems :n :thing
if or :n <= 0 empty? :thing [output :thing]
output butitems :n-1 butfirst :thing
end
to middle :n :m :thing
output items :m-(:n-1) butitems :n-1 :thing
end
to lastitems :n :thing
if :n >=... |
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.
| #RPN_.28HP-15c.29 | RPN (HP-15c) | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Register And Flag Usage
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 0 General purpose variable used for miscelaneous purposes
; 1 Current index (0-80) in the ps... |
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... | #Raven | Raven | define println use $s
$s print "\n" print
"0123456789" as $str
define offTheTop use $s
$s 1 0x7FFFFFFF extract
define offTheTail use $s
$s 0 -1 extract
$str offTheTop println
$str offTheTail println
$str offTheTop offTheTail 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... | #REXX | REXX | /*REXX program demonstrates removal of 1st/last/1st-and-last characters from a string.*/
@ = 'abcdefghijk'
say ' the original string =' @
say 'string first character removed =' substr(@, 2)
say 'string last character removed =' left(@, length(@) -1)
say 'string first & last characte... |
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.
| #PowerShell | PowerShell | function Get-Sum ($a) {
return ($a | Measure-Object -Sum).Sum
} |
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.
| #Prolog | Prolog | sum([],0).
sum([H|T],X) :- sum(T,Y), X is H + Y.
product([],1).
product([H|T],X) :- product(T,Y), X is H * X. |
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... | #MiniScript | MiniScript | zeta = function(num)
return 1 / num^2
end function
sum = function(start, finish, formula)
total = 0
for i in range(start, finish)
total = total + formula(i)
end for
return total
end function
print sum(1, 1000, @zeta)
|
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... | #.D0.9C.D0.9A-61.2F52 | МК-61/52 | 0 П0 П1 ИП1 1 + П1 x^2 1/x ИП0
+ П0 ИП1 1 0 0 0 - x>=0 03
ИП0 С/П |
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 |... | #Sed | Sed | #!/bin/bash
# Usage example: . interpolate "Mary has a X lamb" "quite annoying"
echo "$1" | sed "s/ X / $2 /g" |
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 |... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: main is func
local
const string: original is "Mary had a X lamb";
const string: little is "little";
var string: replaced is "";
begin
replaced := replace(original, "X", little);
writeln(replaced);
end func; |
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 |... | #SenseTalk | SenseTalk | put "little" into x
put "Mary had a [[x]] lamb." -- this is a literal string
put !"Mary had a [[x]] lamb." -- this is an interpolated string
put
put !"[[repeat with n=2 to 6]]Mary had [[n]] [[x]] lambs.[[return]][[end repeat]]"
put !"Mary had [[repeat with n=2 to 6]][[n]] [[x]] [[end repeat]]lambs."
|
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... | #Raku | Raku | sub strip_chars ( $s, $chars ) {
return $s.trans( $chars.comb X=> '' );
}
say strip_chars( 'She was a soul stripper. She took my heart!', 'aei' ); |
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... | #Red | Red |
stripchars: func [str chars] [trim/with str chars]
stripchars "She was a soul stripper. She took my heart!" "aei" |
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 |... | #R | R | compare <- function(a, b)
{
cat(paste(a, "is of type", class(a), "and", b, "is of type", class(b), "\n"))
if (a < b) cat(paste(a, "is strictly less than", b, "\n"))
if (a <= b) cat(paste(a, "is less than or equal to", b, "\n"))
if (a > b) cat(paste(a, "is strictly greater than", b, "\n"))
if (a >= b) cat(pa... |
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... | #Lingo | Lingo | ----------------------------------------
-- Lower to upper case (ASCII only)
-- @param {string} str
-- @return {string}
----------------------------------------
on toUpper (str)
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
len = str.length
repeat with i = 1 to len
pos = offset(str.char[i], alphabet)
if pos > 0... |
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... | #LiveCode | LiveCode | put upper("alphaBETA") && lower("alphaBETA")
ALPHABETA 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 |... | #Kotlin | Kotlin | // version 1.0.6
fun main(args: Array<String>) {
val s1 = "abracadabra"
val s2 = "abra"
println("$s1 begins with $s2 : ${s1.startsWith(s2)}")
println("$s1 ends with $s2 : ${s1.endsWith(s2)}")
val b = s2 in s1
print("$s1 contains $s2 : $b")
if (b) println(" at locations ${s1.index... |
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... | #IDL | IDL | length = strlen("Hello, world!") |
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... | #Io | Io | "møøse" sizeInBytes |
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... | #NewLISP | NewLISP | (let (str1 "foo")
(println str1)
(let (str2 (string str1 "bar"))
(println str2))) |
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... | #Nim | Nim | let str = "String"
echo str & " literal."
# -> String literal. |
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.
| #Racket | Racket |
#lang racket
(require math)
;;; A naive solution
(define (naive k)
(for/sum ([n (expt 10 k)]
#:when (or (divides? 3 n) (divides? 5 n)))
n))
(for/list ([k 7]) (naive k))
;;; Using the formula for an arithmetic sum
(define (arithmetic-sum a1 n Δa)
; returns a1+a2+...+an
(define an (+ a1 (... |
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
| #Scala | Scala | def sumDigits(x:BigInt, base:Int=10):BigInt=sumDigits(x.toString(base), base)
def sumDigits(x:String, base:Int):BigInt = x map(_.asDigit) 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
| #Smalltalk | Smalltalk | #(3 1 4 1 5 9) inject: 0 into: [:sum :aNumber | sum + aNumber squared] |
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
| #SNOBOL4 | SNOBOL4 | define('ssq(a)i') :(ssq_end)
ssq i = i + 1; ssq = ssq + (a<i> * a<i>) :s(sumsq)f(return)
ssq_end
* # Fill array, test and display
str = '1 2 3 5 7 11 13 17 19 23'; a = array(10)
loop i = i + 1; str len(p) span('0123456789') . a<i> @p :s(loop)
output = str ' -> ' sumsq(a)
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... | #Smalltalk | Smalltalk | String extend
[
ltrim [
^self replacingRegex: '^\s+' with: ''.
]
rtrim [
^self replacingRegex: '\s+$' with: ''.
]
trim [
^self ltrim rtrim.
]
]
|a|
a := ' this is a string '.
('"%1"' % {a}) displayNl.
('"%1"' % {a ltrim}) displayNl.
('"%1"' % {a rtrim}) displayNl.
('"%... |
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... | #SNOBOL4 | SNOBOL4 | s1 = s2 = " Hello, people of earth! "
s2 = CHAR(3) s2 CHAR(134)
&ALPHABET TAB(33) . prechars
&ALPHABET POS(127) RTAB(0) . postchars
stripchars = " " prechars postchars
* TRIM() removes final spaces and tabs:
OUTPUT = "Original: >" s1 "<"
OUTPUT = "With trim() >" REVERSE(TRIM(REVERSE(TR... |
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 |... | #Logtalk | Logtalk |
:- object(substring).
:- public(test/5).
test(String, N, M, Character, Substring) :-
sub_atom(String, N, M, _, Substring1),
write(Substring1), nl,
sub_atom(String, N, _, 0, Substring2),
write(Substring2), nl,
sub_atom(String, 0, _, 1, Substring3),
write(Subs... |
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.
| #Ruby | Ruby | def read_matrix(data)
lines = data.lines
9.times.collect { |i| 9.times.collect { |j| lines[i][j].to_i } }
end
def permissible(matrix, i, j)
ok = [nil, *1..9]
check = ->(x,y) { ok[matrix[x][y]] = nil if matrix[x][y].nonzero? }
# Same as another in the column isn't permissible...
9.times { |x| check[x, j] ... |
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... | #Ring | Ring |
aString = "1Welcome to the Ring Programming Language2"
see substr(aString,2,len(aString)-1) + nl +
substr(aString,1,len(aString)-1) + nl +
substr(aString,2,len(aString)-2) + 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.
| #PureBasic | PureBasic | Dim MyArray(9)
Define a, sum=0, prod=1
For a = 0 To ArraySize(MyArray()) ; Create a list of some random numbers
MyArray(a) = 1 + Random(9) ; Insert a number [1...10] in current element
Next
For a = 0 To ArraySize(MyArray()) ; Calculate Sum and Product of this Array
sum + MyArray(a)
prod * My... |
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... | #ML | ML |
(* 1.64393456668 *)
List.foldl op+ 0.0 (List.tabulate(1000, fn x => 1.0 / Math.pow(real(x + 1),2.0)))
|
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 |... | #Sidef | Sidef | var extra = 'little';
say "Mary had a #{extra} 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 |... | #SNOBOL4 | SNOBOL4 | s1 = "Mary had a humongous lamb."
s2 = "humongous"
s3 = "little"
s1 s2 = s3
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... | #REXX | REXX | /*REXX program removes a list of characters from a string (the haystack). */
say stripChars('She was a soul stripper. She took my heart!', "iea") /*elide: iea */
exit /*stick a fork in it, we're all done. */
/*─────────────────────────────────────────────... |
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 |... | #Racket | Racket |
#lang racket
;; Comparing two strings for exact equality
(string=? "foo" "foo")
;; Comparing two strings for inequality
(not (string=? "foo" "bar"))
;; Comparing two strings to see if one is lexically ordered before than the other
(string<? "abc" "def")
;; Comparing two strings to see if one is lexically orde... |
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... | #Logo | Logo | print uppercase "alphaBETA ; ALPHABETA
print lowercase "alphaBETA ; 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... | #Lua | Lua | str = "alphaBETA"
print( string.upper(str) )
print( string.lower(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 |... | #Ksh | Ksh |
#!/bin/ksh
exec 2> /tmp/String_matching.err
# String matching
# # 1. Determine if the first string starts with second string.
# # 2. Determine if the first string contains the second string at any location
# # 3. Determine if the first string ends with the second string
# # 4. Print the location of the match for pa... |
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... | #J | J | # 'møøse'
7 |
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... | #NS-HUBASIC | NS-HUBASIC | 10 STRING$="HELLO"
20 STRING$=STRING$+" WORLD!"
30 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... | #Objeck | Objeck | bundle Default {
class Repeat {
function : Main(args : String[]) ~ Nil {
s := "hello";
s->PrintLine();
" literal"->PrintLine();
s->Append(" literal");
s->PrintLine();
}
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.