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/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 |...
#Racket
Racket
  #lang racket   (define str "abcdefghijklmnopqrstuvwxyz")   (define n 10) (define m 2) (define start-char #\x) (define start-str "xy")   ;; starting from n characters in and of m length; (substring str n (+ n m)) ; -> "kl"   ;; starting from n characters in, up to the end of the string; (substring str m) ; -> "klmnopq...
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 |...
#Raku
Raku
my $str = 'abcdefgh'; my $n = 2; my $m = 3; say $str.substr($n, $m); say $str.substr($n); say $str.substr(0, *-1); say $str.substr($str.index('d'), $m); say $str.substr($str.index('de'), $m);
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.
#WDTE
WDTE
let a => import 'arrays'; let s => import 'stream';   let sum array => a.stream array -> s.reduce 0 +; let prod array => a.stream prod -> s.reduce 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.
#Wortel
Wortel
@sum [1 2 3 4] ; returns 10 @prod [1 2 3 4] ; returns 24
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...
#Ring
Ring
  sum = 0 for i =1 to 1000 sum = sum + 1 /(pow(i,2)) next decimals(8) see sum  
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...
#REXX
REXX
abc = "abcdefghijklmnopqrstuvwxyz" /*define all lowercase Latin letters.*/ abcU = translate(abc) /* " " uppercase " " */   x = 'alphaBETA' /*define a string to a REXX variable. */ y = translate(x) ...
http://rosettacode.org/wiki/String_case
String case
Task Take the string     alphaBETA     and demonstrate how to convert it to:   upper-case     and   lower-case Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional...
#Ring
Ring
  aString = "WELCOME TO THE ring programming language" see lower(aString) + nl see upper(aString) + nl  
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 |...
#Raku
Raku
$haystack.starts-with($needle) # True if $haystack starts with $needle $haystack.contains($needle) # True if $haystack contains $needle $haystack.ends-with($needle) # True if $haystack ends with $needle
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 |...
#Retro
Retro
: startsWith? ( $1 $2 - f ) withLength &swap dip 0 swap ^strings'getSubset compare ;   "abcdefghijkl" "abcde" startsWith? "abcdefghijkl" "bcd" startsWith?   "abcdefghijkl" "bcd" ^strings'search "abcdefghijkl" "zmq" ^strings'search   : endsWith? ( $1 $2 - f ) swap withLength + over getLength - compare ;   "abcdefghi...
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...
#PHP
PHP
<?php foreach (array('møøse', '𝔘𝔫𝔦𝔠𝔬𝔡𝔢', 'J̲o̲s̲é̲') as $s1) { printf('String "%s" measured with strlen: %d mb_strlen: %s grapheme_strlen %s%s', $s1, strlen($s1),mb_strlen($s1), grapheme_strlen($s1), PHP_EOL); }  
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...
#PicoLisp
PicoLisp
(let Str "møøse" (prinl "Character Length of \"" Str "\" is " (length Str)) (prinl "Byte Length of \"" Str "\" is " (size Str)) )
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...
#Yorick
Yorick
var1 = "Hello"; var2 = var1 + ", world!"; write, var1; write, var2;
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...
#Zig
Zig
const std = @import("std");   const debug = std.debug; const heap = std.heap; const mem = std.mem;   test "string concatenation" { const hello = "Hello,";   debug.warn("\n{}{}\n", .{ hello, " world!" });   // Method 1: Array concatenation // // This only works if the values are known at compile-time...
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...
#zkl
zkl
var s="Hello"; s2:=s+", world!"; s2.println(); //-->Hello, world! s3:=String(s," ",s2); s3.println(); //-->Hello Hello, world!
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 |...
#Raven
Raven
define println use $s $s print "\n" print   "0123456789" as $str   $str 3 2 extract println # at 4th pos get 2 chars $str 8 4 extract println # at 9th pos get 4 chars (when only 1 char available)     $str 3 $str length extract println # at 4th pos get all chars to end of str $str 3 0x7FFFFFFF extr...
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 |...
#REBOL
REBOL
rebol [ Title: "Retrieve Substring" URL: http://rosettacode.org/wiki/Substring#REBOL ]   s: "abcdefgh" n: 2 m: 3 char: #"d" chars: "cd"   ; Note that REBOL uses base-1 indexing. Strings are series values, ; just like blocks or lists so I can use the same words to manipulate ; them. All these examples use the 'cop...
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.
#Wren
Wren
import "/math" for Nums var a = [7, 10, 2, 4, 6, 1, 8, 3, 9, 5] System.print("Array  : %(a)") System.print("Sum  : %(Nums.sum(a))") System.print("Product : %(Nums.prod(a))")
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.
#XPL0
XPL0
code CrLf=9, IntOut=11;   func SumProd(A, L); int A, L; int S, P, I; [S:= 0; P:= 1; for I:= 0 to L-1 do [S:= S+A(I); P:= P*A(I)]; IntOut(0, S); CrLf(0); IntOut(0, P); CrLf(0); ]; \SumSq   SumProd([1,2,3,4,5,6,7,8,9,10], 10)
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...
#RLaB
RLaB
  >> sum( (1 ./ [1:1000]) .^ 2 ) - const.pi^2/6 -0.000999500167  
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...
#Ruby
Ruby
puts (1..1000).inject{ |sum, x| sum + 1.0 / x ** 2 }
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...
#Ruby
Ruby
"alphaBETA".downcase # => "alphabeta" "alphaBETA".upcase # => "ALPHABETA"   "alphaBETA".swapcase # => "ALPHAbeta" "alphaBETA".capitalize # => "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...
#Rust
Rust
fn main() { println!("{}", "jalapeño".to_uppercase()); // JALAPEÑO println!("{}", "JALAPEÑO".to_lowercase()); // jalapeño }
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 |...
#REXX
REXX
/*REXX program demonstrates some basic character string testing (for matching). */ parse arg A B /*obtain A and B from the command line.*/ say 'string A = ' A /*display string A to the terminal.*/ say 'string B = ' B ...
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...
#PL.2FI
PL/I
declare WS widechar (13) initial ('Hello world.'); put ('Character length=', length (WS)); put skip list ('Byte length=', size(WS));   declare SM graphic (13) initial ('Hello world'); put ('Character length=', length(SM)); put skip list ('Byte length=', size(trim(SM)));
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...
#Zoea
Zoea
  program: string_concat input: ['hello', 'literal'] output: 'hello literal'  
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 |...
#ReScript
ReScript
let s = "ABCDEFGH" let from = 2 let length = 3   Js.log2("Original string: ", s)   Js.log(Js.String.substrAtMost(~from, ~length, s)) Js.log(Js.String.substr(~from, s)) Js.log(Js.String.substrAtMost(~from=0, ~length=(Js.String2.length(s) - 1), s))   Js.log(Js.String.substrAtMost(~from=(Js.String.indexOf("B", s)), ~lengt...
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.
#XSLT
XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" />   <xsl:template name="sum-prod"> <xsl:param name="values" /> <xsl:param name="sum" select="0" /> <xsl:param name="prod" select="1" /> <xsl:choose> <xsl:when test="not($values)"> ...
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...
#Run_BASIC
Run BASIC
  for i =1 to 1000 sum = sum + 1 /( i^2) next i print sum
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...
#Scala
Scala
val s="alphaBETA" println(s.toUpperCase) //-> ALPHABETA println(s.toLowerCase) //-> alphabeta println(s.capitalize) //-> AlphaBETA println(s.reverse) //-> ATEBahpla
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...
#Scheme
Scheme
(define s "alphaBETA") (list->string (map char-upcase (string->list s))) (list->string (map char-downcase (string->list s)))
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 |...
#Ring
Ring
  aString = "Welcome to the Ring Programming Language" bString = "Ring" bStringIndex = substr(aString,bString) if bStringIndex > 0 see "" + bStringIndex + " : " + bString ok  
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 |...
#Ruby
Ruby
p 'abcd'.start_with?('ab') #returns true p 'abcd'.end_with?('ab') #returns false p 'abab'.include?('bb') #returns false p 'abab'.include?('ab') #returns true p 'abab'['bb'] #returns nil p 'abab'['ab'] #returns "ab" p 'abab'.index('bb') #returns nil p 'abab'.index('ab') ...
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...
#PL.2FSQL
PL/SQL
DECLARE string VARCHAR2(50) := 'Hello, world!'; stringlength NUMBER; BEGIN stringlength := LENGTHB(string); END;
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 |...
#REXX
REXX
/*REXX program demonstrates various ways to extract substrings from a string of characters.*/ $='abcdefghijk'; n=4; m=3 /*define some constants: string, index, length of string. */ say 'original string='$ /* [↑] M can be zero (which indicates a null string).*/ L=length($) ...
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.
#Yabasic
Yabasic
dim array(5) data 1, 2, 3, 4, 5 for index = 1 to arraysize(array(), 1) read array(index) next index   sum = 0 prod = 1 for index = 1 to arraysize(array(), 1) sum = sum + array(index) prod = prod * array(index) next index print "The sum is ", sum //15 print "and the product is ", prod //120 end
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.
#zkl
zkl
fcn sum(vals){vals.reduce('+,0)} fcn product(vals){vals.reduce('*,1)}
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...
#Rust
Rust
const LOWER: i32 = 1; const UPPER: i32 = 1000;   // Because the rule for our series is simply adding one, the number of terms are the number of // digits between LOWER and UPPER const NUMBER_OF_TERMS: i32 = (UPPER + 1) - LOWER; fn main() { // Formulaic method println!("{}", (NUMBER_OF_TERMS * (LOWER + UPPER)) /...
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...
#Sed
Sed
echo "alphaBETA" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' echo "alphaBETA" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'
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...
#Seed7
Seed7
writeln(upper("alphaBETA")); writeln(lower("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 |...
#Run_BASIC
Run BASIC
s1$ = "abc def ghi klmnop" s2$ = "abc" ' begins with s3$ = "ef" ' is in the string s4$ = "nop" ' ends with   sn2$ = "abcx" ' not begins with sn3$ = "efx" ' not in the string sn4$ = "nopx" ' not ends with   if left$(s1$,len(s2$)) <> s2$ then a$ = "Not " print "String:";s1$;" does ";a$;"begin with:";s2$   if...
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 |...
#Rust
Rust
fn print_match(possible_match: Option<usize>) { match possible_match { Some(match_pos) => println!("Found match at pos {}", match_pos), None => println!("Did not find any matches") } }   fn main() { let s1 = "abcd"; let s2 = "abab"; let s3 = "ab";   // Determining if the first st...
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...
#Pop11
Pop11
lvars str = 'Hello, world!'; lvars len = length(str);
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...
#PostScript
PostScript
  (Hello World) length = 11  
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 |...
#Ring
Ring
cStr = "a":"h" # 'abcdefgh' n = 3 m = 3 # starting from n characters in and of m length See substr(cStr,n, m) + nl #=> cde # starting from n characters in, up to the end of the string See substr(cStr,n) + nl #=> cdefgh # whole string minus last character See substr(cstr,1,len(cStr)-1) + nl #=> ab...
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.
#Zoea
Zoea
  program: sum_and_product case: 1 input: [3,5] output: [8,15] case: 2 input: [2,3,4] output: [9,24]  
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...
#SAS
SAS
data _null_; s=0; do n=1 to 1000; s+1/n**2; /* s+x is synonym of s=s+x */ end; e=s-constant('pi')**2/6; put s e; run;
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...
#Scala
Scala
scala> 1 to 1000 map (x => 1.0 / (x * x)) sum res30: Double = 1.6439345666815615
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...
#SenseTalk
SenseTalk
  set letters to "alphaBETA" put lowercase of letters // alphabeta put uppercase of letters // ALPHABETA put capitalized of letters // Alphabeta   repeat with each character of letters by reference if it is an uppercase set it to lowercase of it else set it to uppercase of it end if end repeat   put letters //AL...
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...
#Sidef
Sidef
say "alphaBETA".lc; #=> alphabeta say "alphaBETA".uc; #=> ALPHABETA say "alphaBETA".tc; #=> AlphaBETA say "alpha BETA".wc; #=> Alpha Beta say "alpha BETA".tc; #=> Alpha BETA say "alpha BETA".tclc; #=> Alpha beta
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 |...
#Scala
Scala
"abcd".startsWith("ab") //returns true "abcd".endsWith("zn") //returns false "abab".contains("bb") //returns false "abab".contains("ab") //returns true   var loc="abab".indexOf("bb") //returns -1 loc = "abab".indexOf("ab") //returns 0 loc = "abab".indexOf("ab", loc+1) //returns 2
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 |...
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func local var integer: position is 0; begin writeln(startsWith("abcd", "ab")); # write TRUE writeln(endsWith("abcd", "zn")); # write FALSE writeln(pos("abab", "bb") <> 0); # write FALSE writeln(pos("abab", "ab") <> 0); # write TRUE write...
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...
#Potion
Potion
"møøse" length print "𝔘𝔫𝔦𝔠𝔬𝔡𝔢" length print "J̲o̲s̲é̲" length 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...
#PowerShell
PowerShell
$s = "Hëlló Wørłð" $s.Length
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 |...
#RPG
RPG
* 1...5....1....5....2....5.. D myString S 30 inz('Liebe bewegt das Universum!') D output S 30 inz('') D n S 2 0 inz(1) ...
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 |...
#Ruby
Ruby
str = 'abcdefgh' n = 2 m = 3 puts str[n, m] #=> cde puts str[n..m] #=> cd puts str[n..-1] #=> cdefgh puts str[0..-2] #=> abcdefg puts str[str.index('d'), m] #=> def puts str[str.index('de'), m] #=> def puts str[/a.*d/] #=> abcd
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...
#Scheme
Scheme
(define (sum a b fn) (do ((i a (+ i 1)) (result 0 (+ result (fn i)))) ((> i b) result)))   (sum 1 1000 (lambda (x) (/ 1 (* x x)))) ; fraction (exact->inexact (sum 1 1000 (lambda (x) (/ 1 (* x x))))) ; decimal
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...
#Simula
Simula
TEXT soup, lower; soup :- "alphaBETA"; lower :- LOWCASE(COPY(soup)); ! COPY, else soup is changed; OutText("upper: "); OutText(UPCASE("alphaBETA")); OutText(", lower: "); OutText(lower); OutText(", soup: "); OutText(soup); Outimage;
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...
#Slate
Slate
'alphaBETA' toLowercase. 'alphaBETA' toUppercase.
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 |...
#Sidef
Sidef
var first = "abc-abcdef-abcd"; var second = "abc";   say first.begins_with(second); #=> true say first.contains(second); #=> true say first.ends_with(second); #=> false   # Get and print the location of the match say first.index(second); #=> 0   # Find multiple occurrences of a string var...
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 |...
#Smalltalk
Smalltalk
a startsWith: b a includesSubCollection: b. "inherited from superclass" a includesString: b. "the same, but more readable" a endsWith: b a indexOfSubCollection: b "inherited" a indexOfSubCollection: b startingAt: pos "inherited" a indexOfString: b a indexOfStringStartingAt: b  
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...
#PureBasic
PureBasic
a = Len("Hello World") ;a will be 11
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...
#Python
Python
print len('ascii') # 5
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 |...
#Run_BASIC
Run BASIC
n = 2 m = 3 s$ = "abcd" a$ = mid$(a$,n,m) ' starting from n characters in and of m length a$ = mid$(a$,n) ' starting from n characters in, up to the end of the string a$ = Print mid$(a$,1,(len(a$)-1)) ' whole string minus last character a$ = mid$(a$,instr(a$,s$,1),m) ' startin...
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 |...
#Rust
Rust
  let s = "abc文字化けdef"; let n = 2; let m = 3;   // Print 3 characters starting at index 2 (c文字) println!("{}", s.chars().skip(n).take(m).collect::<String>());   // Print all characters starting at index 2 (c文字化けdef) println!("{}", s.chars().skip(n).collect::<String>());   // Print all characters except the ...
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...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "float.s7i";   const func float: invsqr (in float: n) is return 1.0 / n**2;   const proc: main is func local var integer: i is 0; var float: sum is 0.0; begin for i range 1 to 1000 do sum +:= invsqr(flt(i)); end for; writeln(sum digits 6 lpad 8); end...
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...
#Sidef
Sidef
say sum(1..1000, {|n| 1 / n**2 })
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...
#Smalltalk
Smalltalk
'ALPHAbeta' asUppercase "->'ALPHABETA' " 'ALPHAbeta' asLowercase "-> '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...
#SNOBOL4
SNOBOL4
define('uc(str)') :(uc_end) uc uc = replace(str,&lcase,&ucase) :(return) uc_end   define('lc(str)') :(lc_end) lc lc = replace(str,&ucase,&lcase) :(return) lc_end   define('ucfirst(str)ch') :(ucfirst_end) ucfirst str len(1) . ch = uc(ch) ucfirst = str :(return) ucfirst_end   ...
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 |...
#SNOBOL4
SNOBOL4
s1 = 'abcdabefgab' s2 = 'ab' s3 = 'xy' OUTPUT = ?(s1 ? POS(0) s2) "1. " s2 " begins " s1 OUTPUT = ?(s1 ? POS(0) s3) "1. " s3 " begins " s1  ;# fails   n = 0 again s1 POS(n) ARB s2 @a  :F(p3) OUTPUT = "2. " s2 " found at position " + a - SIZE(s2) "...
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 |...
#Standard_ML
Standard ML
String.isPrefix "ab" "abcd"; (* returns true *) String.isSuffix "zn" "abcd"; (* returns false *) String.isSubstring "bb" "abab"; (* returns false *) String.isSubstring "ab" "abab"; (* returns true *) #2 (Substring.base (#2 (Substring.position "bb" (Substring.full "abab")))); (* returns 4 *) val loc = #2 (Substring.base...
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...
#R
R
a <- "m\u00f8\u00f8se" print(nchar(a, type="bytes")) # print 7
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 |...
#SAS
SAS
data _null_; a="abracadabra"; b=substr(a,2,3); /* first number is position, starting at 1, second number is length */ put _all_; run;
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...
#Slate
Slate
((1 to: 1000) reduce: [|:x :y | x + (y squared reciprocal as: Float)]).
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...
#SQL
SQL
DECLARE @s VARCHAR(10) SET @s = 'alphaBETA' print UPPER(@s) print LOWER(@s)
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...
#SQL_PL
SQL PL
  VALUES UPPER('alphaBETA'); VALUES LOWER('alphaBETA'); VALUES initcap('alphaBETA'); -- Within a SQL query. SELECT UPPER('alphaBETA') FROM sysibm.sysdummy1;  
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 |...
#Swift
Swift
var str = "Hello, playground" str.hasPrefix("Hell") //True str.hasPrefix("hell") //False   str.containsString("llo") //True str.containsString("xxoo") //False   str.hasSuffix("playground") //True str.hasSuffix("world") //False
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 |...
#Tailspin
Tailspin
  templates find&{s:} when <'$s;.*'> do '$; starts with $s;' ! when <'.*$s;'> do '$; ends with $s;' ! when <'.*$s;.*'> do '$; contains $s;' ! otherwise '$s; cannot be found in $;' ! end find   'abcd' -> find&{s:'ab'} -> !OUT::write ' ' -> !OUT::write 'abcd' -> find&{s:'cd'} -> !OUT::write ' ' -> !OUT::write 'ab...
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...
#Racket
Racket
(define str "J\u0332o\u0332s\u0332e\u0301\u0332")
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 |...
#Sather
Sather
class MAIN is main is s ::= "hello world shortest program"; #OUT + s.substring(12, 5) + "\n"; #OUT + s.substring(6) + "\n"; #OUT + s.head( s.size - 1) + "\n"; #OUT + s.substring(s.search('w'), 5) + "\n"; #OUT + s.substring(s.search("ro"), 3) + "\n"; end; end;
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 |...
#Scala
Scala
object Substring { // Ruler 1 2 3 4 5 6 // 012345678901234567890123456789012345678901234567890123456789012 val str = "The good life is one inspired by love and guided by knowledge." val (n, m) = (21, 16) // An one-liner to set n = 21, m = 16   // Sta...
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...
#Smalltalk
Smalltalk
( (1 to: 1000) fold: [:sum :aNumber | sum + (aNumber squared reciprocal) ] ) asFloat displayNl.
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...
#Standard_ML
Standard ML
val strupr = String.map Char.toUpper; val strlwr = String.map Char.toLower;
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...
#Stata
Stata
. scalar s="alphaBETA" . di strupper(s) ALPHABETA . di strlower(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 |...
#Tcl
Tcl
set isPrefix [string equal -length [string length $needle] $haystack $needle] set isContained [expr {[string first $needle $haystack] >= 0}] set isSuffix [string equal $needle [string range $haystack end-[expr {[string length $needle]-1}] end]]
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...
#Raku
Raku
say 'møøse'.encode('UTF-8').bytes;
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...
#REBOL
REBOL
;; r2 length? "møøse"   ;; r3 length? to-binary "møøse"
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 |...
#Scheme
Scheme
(define s "Hello, world!") (define n 5) (define m (+ n 6))   (display (substring s n m)) (newline)   (display (substring s n)) (newline)   (display (substring s 0 (- (string-length s) 1))) (newline)   (display (substring s (string-index s #\o) m)) (newline)   (display (substring s (string-contains s "lo") m)) (newline)
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...
#SQL
SQL
CREATE TABLE t1 (n REAL); -- this is postgresql specific, fill the table INSERT INTO t1 (SELECT generate_series(1,1000)::REAL); WITH tt AS ( SELECT 1/(n*n) AS recip FROM t1 ) SELECT SUM(recip) FROM tt;  
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...
#Swift
Swift
import Foundation   println("alphaBETA".uppercaseString) println("alphaBETA".lowercaseString) println("foO BAr".capitalizedString)
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...
#Tcl
Tcl
set string alphaBETA   # three built-in case conversion commands string toupper $string ;# ==> ALPHABETA string tolower $string ;# ==> alphabeta string totitle $string ;# ==> Alphabeta   # not built-in proc swapcase {s} { foreach char [split $s ""] { if {$char eq [set CHAR [string toupper $char]]} { ...
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 |...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT ASK "string1", string1="" ASK "string2", string2=""   IF (string1.sw.string2) THEN PRINT string1," starts with ",string2 ELSE PRINT string1," not starts with ",string2 ENDIF SET beg=STRING (string1,string2,0,0,0,end) IF (beg!=0) THEN PRINT string1," contains ",string2 PRINT " starting i...
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...
#ReScript
ReScript
Js.String2.length("abcd") == 4
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 |...
#Sed
Sed
  # 2 chars starting from 3rd $ echo string | sed -r 's/.{3}(.{2}).*/\1/' in # remove first 3 chars echo string | sed -r 's/^.{3}//' # delete last char $ echo string | sed -r 's/.$//' strin # `r' with two following chars $ echo string | sed -r 's/.*(r.{2}).*/\1/' rin  
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...
#Stata
Stata
function series(n) { return(sum((n..1):^-2)) }   series(1000)-pi()^2/6 -.0009995002
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...
#Toka
Toka
needs ctype [ i 1 - ] is i [ string.getLength 0 [ dup i + c@ toupper over i + c! ] countedLoop ] is string.toUpper [ string.getLength 0 [ dup i + c@ tolower over i + c! ] countedLoop ] is string.toLower " alphaBETA" string.toUpper type cr " alphaBETA" string.toLower type 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...
#TorqueScript
TorqueScript
$string = "alphaBETA"; $upperCase = strUpr($string); $lowerCase = strLwr($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 |...
#TXR
TXR
(tree-case *args* ((big small) (cond ((< (length big) (length small)) (put-line `@big is shorter than @small`)) ((str= big small) (put-line `@big and @small are equal`)) ((starts-with small big) (put-line `@small is a prefix of @big`)) ((ends-with small big) (put-line `@...
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 |...
#Vala
Vala
void main() { var text = "一二三四五六七八九十"; var starts = "一二"; var ends = "九十"; var contains = "五六"; var not_contain = "百";   stdout.printf(@"text: $text\n\n", ); stdout.printf(@"starts with $starts: $(text.has_prefix(starts))\n"); stdout.printf(@"ends with $ends: $(text.has_suffix(ends))\n")...
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...
#Retro
Retro
'møøse s:length n:put
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...
#REXX
REXX
/*REXX program displays the lengths (in bytes/characters) for various strings. */ /* 1 */ /*a handy-dandy over/under scale.*/ /* 123456789012345 */ hello = 'Hello, world!'  ; say 'the length of HELLO is ' length(hello) happy = 'Hello, world!...