task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Sum_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
#Perl
Perl
sub sum_of_squares { my $sum = 0; $sum += $_**2 foreach @_; return $sum; }   print sum_of_squares(3, 1, 4, 1, 5, 9), "\n";
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...
#NewLISP
NewLISP
(setq str " this is a string ")   ;; trim leading blanks (trim str " " "")   ;; trim trailing blanks (trim str "" " ")   ;; trim both leading and trailing blanks (trim str)
http://rosettacode.org/wiki/Strip_whitespace_from_a_string/Top_and_tail
Strip whitespace from a string/Top and tail
Task Demonstrate how to strip leading and trailing whitespace from a string. The solution should demonstrate how to achieve the following three results: String with leading whitespace removed String with trailing whitespace removed String with both leading and trailing whitespace removed For the purposes of thi...
#Nim
Nim
import strutils   let s = "\t \v \r String with spaces \n \t \f" echo "“", s, "”" echo("*** Stripped of leading spaces ***") echo "“", s.strip(trailing = false), "”" echo("*** Stripped of trailing spaces ***") echo "“", s.strip(leading = false), "”" echo("*** Stripped of leading and trailing spaces ***") echo "“", s.st...
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 |...
#Groovy
Groovy
def str = 'abcdefgh' def n = 2 def m = 3 // #1 println str[n..n+m-1] /* or */ println str[n..<(n+m)] // #2 println str[n..-1] // #3 println str[0..-2] // #4 def index1 = str.indexOf('d') println str[index1..index1+m-1] /* or */ println str[index1..<(index1+m)] // #5 def index2 = str.indexOf('de') println str[index2..in...
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.
#OCaml
OCaml
(* Ocamlgraph demo program: solving the Sudoku puzzle using graph coloring Copyright 2004-2007 Sylvain Conchon, Jean-Christophe Filliatre, Julien Signoles   This software is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2, with the...
http://rosettacode.org/wiki/Subleq
Subleq
Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Task Your task is to create an interpreter which emulates a SUBLEQ machine. The machine's memory consists of an array of signed integers.   These integers...
#REXX
REXX
/*REXX program simulates the execution of a One─Instruction Set Computer (OISC). */ signal on halt /*enable user to halt the simulation.*/ parse arg $ /*get optional low memory vals from CL.*/ $$= '15 17 -1 17 -1 -1 16 1 -1 16 3 -1 15 15 0 ...
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...
#NetRexx
NetRexx
/********************************************************************** * 02.08.2013 Walter Pachl translated from REXX **********************************************************************/ z = 'abcdefghijk' l=z.length() say ' the original string =' z If l>=1 Then Do Say 'string first charac...
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.
#Modula-3
Modula-3
MODULE Sumprod EXPORTS Main;   FROM IO IMPORT Put; FROM Fmt IMPORT Int;   VAR a := ARRAY [1..5] OF INTEGER {1, 2, 3, 4, 5}; VAR sum: INTEGER := 0; VAR prod: INTEGER := 1;   BEGIN FOR i := FIRST(a) TO LAST(a) DO INC(sum, a[i]); prod := prod * a[i]; END; Put("Sum of array: " & Int(sum) & "\n"); Put("Produ...
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...
#jq
jq
def s(n): reduce range(1; n+1) as $k (0; . + 1/($k * $k) );   s(1000)  
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#Standard_ML
Standard ML
val stripComment = let val notMarker = fn #"#" => false | #";" => false | _ => true open Substring in string o dropr Char.isSpace o takel notMarker o full end
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#Tcl
Tcl
proc stripLineComments {inputString {commentChars ";#"}} { # Switch the RE engine into line-respecting mode instead of the default whole-string mode regsub -all -line "\[$commentChars\].*$" $inputString "" commentStripped # Now strip the whitespace regsub -all -line {^[ \t\r]*(.*\S)?[ \t\r]*$} $commentS...
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#TUSCRIPT
TUSCRIPT
$$ MODE TUSCRIPT strngcomment=* DATA apples, pears # and bananas DATA apples, pears ; and bananas   BUILD S_TABLE comment_char="|#|;|"   LOOP s=strngcomment x=SPLIT (s,comment_char,string,comment) PRINT string ENDLOOP
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 |...
#Julia
Julia
X = "little" "Mary had a $X 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 |...
#Kotlin
Kotlin
// version 1.0.6   fun main(args: Array<String>) { val s = "little" // String interpolation using a simple variable println("Mary had a $s lamb")   // String interpolation using an expression (need to wrap it in braces) println("Mary had a ${s.toUpperCase()} lamb")   // However if a simple variab...
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 |...
#Lambdatalk
Lambdatalk
  {def original Mary had a X lamb} -> original {def Y little} -> Y {S.replace X by {Y} in {original}} -> 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...
#Lasso
Lasso
define stripper(in::string,destroy::string) => { with toremove in #destroy->values do => { #in->replace(#toremove,'') } return #in } stripper('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...
#Liberty_BASIC
Liberty BASIC
Print stripchars$("She was a soul stripper. She took my heart!", "aei", 1) End   Function stripchars$(strip$, chars$, num) For i = 1 To Len(strip$) If Mid$(strip$, i, 1) <> Mid$(chars$, num, 1) Then stripchars$ = (stripchars$ + Mid$(strip$, i, 1)) End If Next i If (num <= Len(cha...
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#Wart
Wart
s <- "12345678" s <- ("0" + s)
http://rosettacode.org/wiki/String_prepend
String prepend
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Wren
Wren
var s = "world!" s = "Hello, " + s System.print(s)
http://rosettacode.org/wiki/String_prepend
String prepend
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 |...
#Xojo
Xojo
Dim s As String = "bar" s = "foo" + s MsgBox(s)
http://rosettacode.org/wiki/String_prepend
String prepend
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#XPL0
XPL0
include xpllib; char S, T(80); [S:= "world!"; S:= StrCat(StrCopy(T,"Hello, "), S); Text(0, S); ]
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 |...
#Icon_and_Unicon
Icon and Unicon
procedure main(A) s1 := A[1] | "a" s2 := A[2] | "b" # These first four are case-sensitive s1 == s2 # Are they equal? s1 ~== s2 # Are they unequal? s1 << s2 # Does s1 come before s2? s1 >> s2 # Does s1 come after s2? map(s1) == map(s2) # Caseless comparison ...
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...
#Erlang
Erlang
string:to_upper("alphaBETA"). string:to_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 |...
#Euphoria
Euphoria
sequence first, second integer x   first = "qwertyuiop"   -- Determining if the first string starts with second string second = "qwerty" if match(second, first) = 1 then printf(1, "'%s' starts with '%s'\n", {first, second}) else printf(1, "'%s' does not start with '%s'\n", {first, second}) end if   -- Determini...
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...
#Delphi
Delphi
"Hello World".Length()
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#Ring
Ring
  s = char(31) + "abc" + char(13) + "def" + char(11) + "ghi" + char(10) see strip(s) + nl   func strip str strip = "" for i = 1 to len(str) nr = substr(str,i,1) a = ascii(nr) if a > 31 and a < 123 and nr != "'" and nr != """" strip = strip + nr ok next return strip  
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#Ruby
Ruby
class String def strip_control_characters() chars.each_with_object("") do |char, str| str << char unless char.ascii_only? and (char.ord < 32 or char.ord == 127) end end   def strip_control_and_extended_characters() chars.each_with_object("") do |char, str| str << char if char.ascii_only? a...
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...
#Groovy
Groovy
def s = "Greetings " println s + "Earthlings"   def s1 = s + "Earthlings" println s1
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#Halon
Halon
echo "Hello" . "World " . 123;
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...
#Haskell
Haskell
import System.IO s = "hello" s1 = s ++ " literal" main = do putStrLn (s ++ " literal") putStrLn s1
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.
#Oforth
Oforth
999 seq filter(#[ dup 3 mod 0 == swap 5 mod 0 == or ]) sum println
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
#Perl
Perl
#!/usr/bin/perl use strict; use warnings;   my %letval = map { $_ => $_ } 0 .. 9; $letval{$_} = ord($_) - ord('a') + 10 for 'a' .. 'z'; $letval{$_} = ord($_) - ord('A') + 10 for 'A' .. 'Z';   sub sumdigits { my $number = shift; my $sum = 0; $sum += $letval{$_} for (split //, $number); $sum; }   print "$_ sums t...
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
#Phix
Phix
function sum_of_squares(sequence s) return sum(sq_power(s,2)) end function ?apply({{},{3,1,4,1,5,9},tagset(10)},sum_of_squares)
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
#Phixmonti
Phixmonti
0 tolist 10 for 0 put endfor   0 swap len for get 2 power rot + swap endfor   drop print /# 385 #/
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...
#Oberon-2
Oberon-2
  MODULE Trim; IMPORT Out,Strings,SYSTEM;   CONST (* whitespaces *) HT = 09X; VT = 0BX; FF = 0CX; GS = 1DX; US = 1FX; LF = 0AX; CR = 0DX; FS = 1CX; RS = 1EX; SPC = 20X;   PROCEDURE LTrim(VAR s: ARRAY OF CHAR); VAR j : INTEGER; BEGIN j := 0; WHILE (s[j] = HT) OR (s[j] = LF) OR (s[j] = VT) OR (s[j] = CR) OR (s...
http://rosettacode.org/wiki/Substring
Substring
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Haskell
Haskell
*Main> take 3 $ drop 2 "1234567890" "345" *Main> drop 2 "1234567890" "34567890" *Main> init "1234567890" "123456789"
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 |...
#HicEst
HicEst
CHARACTER :: string = 'ABCDEFGHIJK', known = 'B', substring = 'CDE' REAL, PARAMETER :: n = 5, m = 8   WRITE(Messagebox) string(n : n + m - 1), "| substring starting from n, length m" WRITE(Messagebox) string(n :), "| substring starting from n, to end of string" WRITE(Messagebox) string(1: LEN(string)-1), "| whole st...
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.
#Oz
Oz
declare %% a puzzle is a function that returns an initial board configuration fun {Puzzle1} %% a board is a list of 9 rows [[4 _ _ _ _ _ _ 6 _] [5 _ _ _ 8 _ 9 _ _] [3 _ _ _ _ 1 _ _ _]   [_ 2 _ 7 _ _ _ _ 1] [_ 9 _ _ _ _ _ 4 _] [8 _ _ _ _ 3 _ 5 _]   [_ _ _ 2 ...
http://rosettacode.org/wiki/Subleq
Subleq
Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Task Your task is to create an interpreter which emulates a SUBLEQ machine. The machine's memory consists of an array of signed integers.   These integers...
#Ruby
Ruby
class Computer def initialize program @memory = program.map &:to_i @instruction_pointer = 0 end   def step return nil if @instruction_pointer < 0   a, b, c = @memory[@instruction_pointer .. @instruction_pointer + 2] @instruction_pointer += 3   if a == -1 b = readchar elsif b == -...
http://rosettacode.org/wiki/Subleq
Subleq
Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Task Your task is to create an interpreter which emulates a SUBLEQ machine. The machine's memory consists of an array of signed integers.   These integers...
#Scala
Scala
import java.util.Scanner   object Subleq extends App { val mem = Array(15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1, 'H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', 10, 0) val input = new Scanner(System.in) var instructionPointer = 0   do { val (a, b) = (mem(instructio...
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...
#NewLISP
NewLISP
(let (str "rosetta") ;; strip first char (println (1 str)) ;; strip last char (println (0 -1 str)) ;; strip both first and last characters (println (1 -1 str)))
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...
#Nim
Nim
import unicode   let s = "Hänsel ««: 10,00€" echo "Original: ", s echo "With first character removed: ", s.runeSubStr(1) echo "With last character removed: ", s.runeSubStr(0, s.runeLen - 1) echo "With first and last characters removed: ", s.runeSubStr(1, s.runeLen - 2) # Using the runes type and slices let r = s.toRun...
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.
#MUMPS
MUMPS
  SUMPROD(A)  ;Compute the sum and product of the numbers in the array A NEW SUM,PROD,POS  ;SUM is the running sum,  ;PROD is the running product,  ;POS is the position within the array A SET SUM=0,PROD=1,POS="" FOR SET POS=$ORDER(A(POS)) Q:POS="" SET SUM=SUM+A(POS),PROD=PROD*A(POS) WRITE !,"The sum of the array...
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.
#Nemerle
Nemerle
using System; using System.Console; using System.Collections.Generic; using Nemerle.Collections;   module SumProd { Sum[T] (nums : T) : int where T : IEnumerable[int] { nums.FoldLeft(0, _+_) }   Product[T] (nums : T) : int where T : IEnumerable[int] { nums.FoldLeft(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...
#Jsish
Jsish
#!/usr/bin/jsish /* Sum of a series */ function sum(a:number, b:number , fn:function):number { var s = 0; for ( ; a <= b; a++) s += fn(a); return s; }   ;sum(1, 1000, function(x) { return 1/(x*x); } );   /* =!EXPECTSTART!= sum(1, 1000, function(x) { return 1/(x*x); } ) ==> 1.643934566681561 =!EXPECTEND!= */
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#UNIX_Shell
UNIX Shell
bash$ a='apples, pears ; and bananas' bash$ b='apples, pears # and bananas' bash$ echo ${a%%;*} apples, pears bash$ echo ${b%%#*} apples, pears bash$
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#VBScript
VBScript
  Function strip_comments(s,char) If InStr(1,s,char) > 0 Then arr = Split(s,char) strip_comments = RTrim(arr(0)) Else strip_comments = s End If End Function   WScript.StdOut.WriteLine strip_comments("apples, pears # and bananas","#") WScript.StdOut.WriteLine strip_comments("apples, pears ; and bananas",";")  
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#Wren
Wren
var markers = ["#", ";"]   var stripComments = Fn.new { |s| for (marker in markers) { var t = s.split(marker) if (t.count > 1) return t[0].trim() } return s.trim() }   var strings = [ " apples, pears # and bananas", " apples, pears ; and bananas", " apples, pears \t " ]   for (s i...
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 |...
#Lasso
Lasso
email_merge("Mary had a #adjective# lamb", map("token"="little", "adjective"=""), null, 'plain')
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 |...
#LiveCode
LiveCode
local str="little" put merge("Mary had a [[str]] lamb.")   -- 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...
#LiveCode
LiveCode
function stripChars str charlist local strstripped put str into strstripped repeat for each char c in charlist replace c with empty in strstripped end repeat return strstripped end stripChars
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...
#Logo
Logo
to strip :string :chars output filter [not substringp ? :chars] :string end   print strip "She\ was\ a\ soul\ stripper.\ She\ took\ my\ heart! "aei   bye
http://rosettacode.org/wiki/String_prepend
String prepend
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#zkl
zkl
s:="bar"; s="foo" + s; s.println(); s:="bar"; s=String("foo",s); s.println(); s:="bar"; s="%s%s".fmt("foo",s); s.println(); // a Data is a byte buffer/editor: s:=Data(Void,"bar").insert(0,"foo").text; s.println();
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 |...
#J
J
eq=: -: NB. equal ne=: -.@-: NB. not equal gt=: {.@/:@,&boxopen *. ne NB. lexically greater than lt=: -.@{.@/:@,&boxopen *. ne NB. lexically less than ge=: {.@/:@,&boxopen +. eq NB. lexically greater than or equal to le=: -.@{.@/:@,&boxopen NB. lexically ...
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 |...
#Java
Java
public class Compare { public static void main (String[] args) { compare("Hello", "Hello"); compare("5", "5.0"); compare("java", "Java"); compare("ĴÃVÁ", "ĴÃVÁ"); compare("ĴÃVÁ", "ĵãvá"); } public static void compare (String A, String B) { if (A.equals...
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...
#Excel
Excel
  =LOWER(A1)  
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...
#F.23
F#
  let s = "alphaBETA" let upper = s.ToUpper() let lower = s.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 |...
#F.23
F#
[<EntryPoint>] let main args =   let text = "一二三四五六七八九十" let starts = "一二" let ends = "九十" let contains = "五六" let notContains = "百"   printfn "text = %A" text printfn "starts with %A: %A" starts (text.StartsWith(starts)) printfn "starts with %A: %A" ends (text.StartsWith(ends)) prin...
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...
#Dyalect
Dyalect
"Hello World".Length()
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#Run_BASIC
Run BASIC
s$ = chr$(31) + "abc" + chr$(13) + "def" + chr$(11) + "ghi" + chr$(10) print strip$(s$)   ' ----------------------------------------- ' strip junk ' ----------------------------------------- FUNCTION strip$(str$) for i = 1 to len(str$) a$ = MID$(str$,i,1) a = ASC(a$) if a > 31 then if a < 123 then if ...
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#Scala
Scala
val controlCode : (Char) => Boolean = (c:Char) => (c <= 32 || c == 127) val extendedCode : (Char) => Boolean = (c:Char) => (c <= 32 || c > 127)     // ASCII test... val teststring = scala.util.Random.shuffle( (1.toChar to 254.toChar).toList ).mkString   println( "ctrl filtered out: \n\n" + teststring.filterNot(contr...
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...
#HicEst
HicEst
CHARACTER s = "hello", sl*100   WRITE() s // " literal" sl = s // " literal" WRITE() sl
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...
#Icon_and_Unicon
Icon and Unicon
procedure main() s1 := "hello" write(s2 := s1 || " there.") # capture the reuslt for write(s2) # ... the 2nd write end
http://rosettacode.org/wiki/Sum_multiples_of_3_and_5
Sum multiples of 3 and 5
Task The objective is to write a function that finds the sum of all positive multiples of 3 or 5 below n. Show output for n = 1000. This is is the same as Project Euler problem 1. Extra credit: do this efficiently for n = 1e20 or higher.
#Ol
Ol
  (print (fold (lambda (s x) (+ s (if (or (zero? (remainder x 3)) (zero? (remainder x 5))) x 0))) 0 (iota 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
#Phix
Phix
function sum_digits(integer n, integer base) integer res = 0 while n do res += remainder(n,base) n = floor(n/base) end while return res end function ?sum_digits(1,10) ?sum_digits(1234,10) ?sum_digits(#FE,16) ?sum_digits(#F0E,16)
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
#PHP
PHP
  function sum_squares(array $args) { return array_reduce( $args, create_function('$x, $y', 'return $x+$y*$y;'), 0 ); }  
http://rosettacode.org/wiki/Sum_of_squares
Sum of squares
Task Write a program to find the sum of squares of a numeric vector. The program should work on a zero-length vector (with an answer of   0). Related task   Mean
#Picat
Picat
go => List = 1..666, println(sum_squares(List)), println(sum_squares([])), nl.   sum_squares([]) = 0. sum_squares(List) = sum([I*I : I in List]).
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...
#Objective-C
Objective-C
#import <Foundation/Foundation.h>   @interface NSString (RCExt) -(NSString *) ltrim; -(NSString *) rtrim; -(NSString *) trim; @end   @implementation NSString (RCExt) -(NSString *) ltrim { NSInteger i; NSCharacterSet *cs = [NSCharacterSet whitespaceAndNewlineCharacterSet]; for(i = 0; i < [self length]; i++) { ...
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 |...
#Icon_and_Unicon
Icon and Unicon
procedure main(arglist) write("Usage: substring <string> <first position> <second position> <single character> <substring>") s := \arglist[1] | "aardvarks" n := \arglist[2] | 5 m := \arglist[3] | 4 c := \arglist[4] | "d" ss := \arglist[5] | "ard"   write( s[n+:m] ) write( s[n:0] ) ...
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.
#PARI.2FGP
PARI/GP
#include <pari/pari.h>   typedef int SUDOKU [9][9];   static inline int check_num(SUDOKU s, int row, int col, int num) { int i, r = (row/3)*3, c = (col/3)*3;   for (i = 0; i < 9; i++) if (s[row][i] == num || s[i][col] == num || s[i%3 + r][i/3 + c] == num) return 0;   return 1; }   static int sudoku_solv...
http://rosettacode.org/wiki/Subleq
Subleq
Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Task Your task is to create an interpreter which emulates a SUBLEQ machine. The machine's memory consists of an array of signed integers.   These integers...
#Sidef
Sidef
var memory = ARGV.map{.to_i}; var ip = 0;   while (ip.ge(0) && ip.lt(memory.len)) { var (a, b, c) = memory[ip, ip+1, ip+2]; ip += 3; if (a < 0) { memory[b] = STDIN.getc.ord; } elsif (b < 0) { print memory[a].chr; } elsif ((memory[b] -= memory[a]) <= 0) { ip = c } ...
http://rosettacode.org/wiki/Subleq
Subleq
Subleq is an example of a One-Instruction Set Computer (OISC). It is named after its only instruction, which is SUbtract and Branch if Less than or EQual to zero. Task Your task is to create an interpreter which emulates a SUBLEQ machine. The machine's memory consists of an array of signed integers.   These integers...
#Sinclair_ZX81_BASIC
Sinclair ZX81 BASIC
10 DIM M(32) 20 INPUT P$ 30 LET W=1 40 LET C=1 50 IF C<LEN P$ THEN GOTO 80 60 LET M(W)=VAL P$ 70 GOTO 150 80 IF P$(C)=" " THEN GOTO 110 90 LET C=C+1 100 GOTO 50 110 LET M(W)=VAL P$( TO C-1) 120 LET P$=P$(C+1 TO ) 130 LET W=W+1 140 GOTO 40 150 LET P=0 160 LET A=M(P+1) 170 LET B=M(P+2) 180 LET C=M(P+3) 190 LET P...
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...
#Objeck
Objeck
  bundle Default { class TopTail { function : Main(args : System.String[]) ~ Nil { string := "test"; string->SubString(1, string->Size() - 1)->PrintLine(); string->SubString(string->Size() - 1)->PrintLine(); string->SubString(1, string->Size() - 2)->PrintLine(); } }...
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.
#NetRexx
NetRexx
/* NetRexx */   options replace format comments java crossref savelog symbols binary   harry = [long 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]   sum = long 0 product = long 1 entries = Rexx ''   loop n_ = int 0 to harry.length - 1 nxt = harry[n_] entries = entries nxt sum = sum + nxt product = product * nxt end n_   en...
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.
#NewLISP
NewLISP
(setq a '(1 2 3 4 5)) (apply + a) (apply * a)
http://rosettacode.org/wiki/Sum_of_a_series
Sum of a series
Compute the   nth   term of a series,   i.e. the sum of the   n   first terms of the corresponding sequence. Informally this value, or its limit when   n   tends to infinity, is also called the sum of the series, thus the title of this task. For this task, use: S n = ∑ k = 1 n 1 k 2 {\displa...
#Julia
Julia
julia> sum(k -> 1/k^2, 1:1000) 1.643934566681559   julia> pi^2/6 1.6449340668482264  
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...
#K
K
ssr: +/1%_sqr ssr 1+!1000 1.643935
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#XProfan
XProfan
  Proc Min Declare int PC, i, float e, t PC = %PCount e = @!(1) If PC > 1 For i, 2, PC t = @!(i) e = if( (e == 0.0) and (t == 0.0), -(-e - t), if(t < e, t, e) ) EndFor EndIf Return e EndProc   Proc Odd Parameters int n Return TestBit(n,0) EndProc   Proc strip_comments ...
http://rosettacode.org/wiki/Strip_comments_from_a_string
Strip comments from a string
Strip comments from a string You are encouraged to solve this task according to the task description, using any language you may know. The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a semicolon) from a string or input line. Whitespace debacle:   There is s...
#zkl
zkl
fcn strip(text,c){ // if c in text, remove it and following text if (Void!=(n:=text.find(c))) text=text[0,n]; text.strip() // remove leading and trailing white space } fcn stripper(text,a,b,c,etc){ // strip a,b,c,etc from text foreach c in (vm.arglist[1,*]){ text=strip(text,c) } text }
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 |...
#Lua
Lua
str = string.gsub( "Mary had a X lamb.", "X", "little" ) print( str )
http://rosettacode.org/wiki/String_interpolation_(included)
String interpolation (included)
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#M2000_Interpreter
M2000 Interpreter
  module checkit { size$="little" m$=format$("Mary had a {0} lamb.", size$) Print m$ Const RightJustify=1 \\ format$(string_expression) process escape codes Report RightJustify, format$(format$("Mary had a {0} {1} lamb.\r\n We use {0} for size, and {1} for color\r\n", size$, "wh"+"i...
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 |...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Extra = "little"; StringReplace["Mary had a X lamb.", {"X" -> 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...
#Lua
Lua
  function stripchars(str, chrs) local s = str:gsub("["..chrs:gsub("%W","%%%1").."]", '') return s end   print( stripchars( "She was a soul stripper. She took my heart!", "aei" ) ) --> Sh ws soul strppr. Sh took my hrt! print( stripchars( "She was a soul stripper. She took my heart!", "a-z" ) ) --> She ws soul st...
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...
#Maple
Maple
with(StringTools):   Remove(c->Has("aei",c), "She was a soul stripper. She took my heart!");
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 |...
#JavaScript
JavaScript
/* == equal value === equal value and equal type != not equal value !== not equal value or not equal type < lexically ordered before > lexically ordered after */   console.log( "abcd" == "abcd", // true "abcd" === "abcd", // true 123 == "123", // true 123 === "123", // false "ABCD" == "abcd", // false "ABCD" != "abcd",...
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 |...
#jq
jq
# Comparing two strings for exact equality: "this" == "this" # true "this" == "This" # false   # != is the inverse of ==   # Comparing two strings to see if one is lexically ordered before the other: "alpha" < "beta" # true "beta" < "alpha" # false   # > is the inverse of <
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...
#Factor
Factor
"alphaBETA" >lower  ! "alphabeta" "alphaBETA" >upper  ! "ALPHABETA" "alphaBETA" >title  ! "Alphabeta" "ß" >case-fold  ! "ss"
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...
#Falcon
Falcon
printl("alphaBETA".lower()) printl("alphaBETA".upper())
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 |...
#Factor
Factor
"cheesecake" "cheese" head?  ! t
http://rosettacode.org/wiki/String_matching
String matching
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Falcon
Falcon
  /* created by Aykayayciti Earl Lamont Montgomery April 9th, 2018 */   s1 = "Naig Ialocin Olracnaig" s2 = "Naig"   var = s1.startsWith(s2) ? s1 + " starts with " + s2 : s1 + " does not start with " + s2 > var   s2 = "loc" var = s2 in s1 ? @ "$s1 contains $s2" : @ "$s1 does not contain $s2" > var   > s1.endsWith(s2) ? ...
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...
#E
E
"Hello World".size()
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...
#Elena
Elena
import extensions;   public program() { var s := "Hello, world!"; // UTF-8 literal var ws := "Привет мир!"w; // UTF-16 literal   var s_length := s.Length; // Number of UTF-8 characters var ws_length := ws.Length; // Number of UTF-16 characters var u_leng...
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "utf8.s7i";   const func string: stripControl (in string: stri) is func result var string: stripped is ""; local var integer: old_pos is 1; var integer: index is 0; var char: ch is ' '; begin for ch key index range stri do if ch < ' ' or ch = '\127;' t...
http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string
Strip control codes and extended characters from a string
Task Strip control codes and extended characters from a string. The solution should demonstrate how to achieve each of the following results:   a string with control codes stripped (but extended characters not stripped)   a string with control codes and extended characters stripped In ASCII, the control codes ...
#Sidef
Sidef
var str = "\ba\x00b\n\rc\fd\xc3\x7ffoo"   var letters = str.chars.map{.ord} say letters.map{.chr}.join.dump   var nocontrols = letters.grep{ (_ > 32) && (_ != 127) } say nocontrols.map{.chr}.join.dump   var noextended = nocontrols.grep{ _ < 127 } say noextended.map{.chr}.join.dump
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...
#IDL
IDL
s1='Hello' print, s1 + ' literal' s2=s1 + ' literal' print, s2
http://rosettacode.org/wiki/String_concatenation
String concatenation
String concatenation You are encouraged to solve this task according to the task description, using any language you may know. Task Create a string variable equal to any text value. Create another string variable whose value is the original variable concatenated with another string literal. To illustrate the operat...
#J
J
s1 =. 'Some ' ]s1, 'text ' Some text ]s2 =. s1 , 'more text!' Some more text!
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...
#Java
Java
public class Str{ public static void main(String[] args){ String s = "hello"; System.out.println(s + " literal"); String s2 = s + " literal"; System.out.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.
#PARI.2FGP
PARI/GP
ct(n,k)=n=n--\k;k*n*(n+1)/2; a(n)=ct(n,3)+ct(n,5)-ct(n,15); a(1000) a(1e20)
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
#PHP
PHP
<?php function sumDigits($num, $base = 10) { $s = base_convert($num, 10, $base); foreach (str_split($s) as $c) $result += intval($c, $base); return $result; } echo sumDigits(1), "\n"; echo sumDigits(12345), "\n"; echo sumDigits(123045), "\n"; echo sumDigits(0xfe, 16), "\n"; echo sumDigits(0xf0e, 16)...
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
#PicoLisp
PicoLisp
: (sum '((N) (* N N)) (3 1 4 1 5 9)) -> 133 : (sum '((N) (* N N)) ()) -> 0