< Programming Fundamentals
Overview
String functions are used in computer programming languages to manipulate a string or query information about a string.[1]
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.
| Function | C++ | C# | Java |
|---|---|---|---|
| case | tolower(), toupper(), etc. |
ToLower(), ToUpper(), etc. |
toLowerCase(), toUpperCase(), etc. |
| comparison | <, >, ==, etc. |
<, >, ==, etc. |
<, >, ==, etc. |
| concatenation | +, += |
+, += |
+, += |
| find | find() |
IndexOf() |
indexOf() |
| join | N/A | Join() |
join() |
| length | length() |
Length |
length() |
| replace | replace() |
Replace() |
replace() |
| reverse | reverse() |
Reverse() |
N/A |
| split | strtok() |
Split() |
split() |
| substring | substr() |
Substring() |
substring() |
| trim | N/A | Trim() |
trim() |
| Function | JavaScript | Python | Swift |
|---|---|---|---|
| case | toLowerCase(), toUpperCase(), etc. |
lower(), upper(), etc. |
lowercased(), uppercased() |
| comparison | <, >, ==, etc. |
<, >, ==, etc. |
<, >, ==, etc. |
| concatenation | +, += |
+, += |
+, += |
| find | indexOf() |
find() |
firstIndex() |
| join | join() |
join() |
joined() |
| length | length |
len() |
count |
| replace | replace() |
replace() |
replacingOccurrences() |
| reverse | N/A | string[::-1] |
reversed() |
| split | split() |
split() |
split() |
| substring | substring() |
string[start:end] |
string[start...end] |
| trim | trim() |
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.[2]
- 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.[3]
- trim
- Remove leading and trailing spaces from a string.[4]
References
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.