411 REFERENCE · Wikibooks
Programming Fundamentals/String Functions
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Overview
String functions are used in computer programming languages to manipulate a string or query information about a string.Wikipedia: Comparison of programming languages (string functions)
Discussion
Most current programming languages include built-in or library functions to process strings. Common examples include case conversion, comparison, concatenation, find, join, length, reverse, split, substring, and trim.
FunctionC++C#Javacasetolower(), toupper(), etc.ToLower(), ToUpper(), etc.toLowerCase(), toUpperCase(), etc.comparison<, >, ==, etc.<, >, ==, etc.<, >, ==, etc.concatenation+, +=+, +=+, +=findfind()IndexOf()indexOf()joinN/AJoin()join()lengthlength()Lengthlength()replacereplace()Replace()replace()reversereverse()Reverse()N/Asplitstrtok()Split()split()substringsubstr()Substring()substring()trimN/ATrim()trim()
FunctionJavaScriptPythonSwiftcasetoLowerCase(), toUpperCase(), etc.lower(), upper(), etc.lowercased(), uppercased()comparison<, >, ==, etc.<, >, ==, etc.<, >, ==, etc.concatenation+, +=+, +=+, +=findindexOf()find()firstIndex()joinjoin()join()joined()lengthlengthlen()countreplacereplace()replace()replacingOccurrences()reverseN/Astring[::-1]reversed()splitsplit()split()split()substringsubstring()string[start:end]string[start...end]trimtrim()strip()trimmingCharacters()
Key Terms
case
A function that either makes a string all uppercase or lowercase depending on which mode is used.
comparison
Determines if the value (string or non-string), is less than, greater than, or equal to the value it's being compared to.
concatenate
Join character strings end-to-end.Wikipedia: Concatenation
find
Checks if a character in a string exists and if it does, finds the location of that character in the string.
join
Joins strings together using a character of the person's choosing.
length
Finds how many characters are in a string, or the number of elements in an array.
replace
Replaces all instances of one character in a string with another.
reverse
Places all characters of a string or elements in an array in reverse order.
split
Divides a string's content onto separate lines based off a chosen character.
substring
Creates a smaller string by using characters from a bigger string.Wikipedia: Substring
trim
Remove leading and trailing spaces from a string.Wikipedia: Trimming (computer programming)
References