WolframLang: String Functions
There are about 100 functions on string. this page lists the most useful ones.
StringQ
- return True if argument is string. StringQ
Length
StringLength
- return the count of chars.
StringLength
StringLength["abc"] === 3
Join String
(for list to string, use StringRiffle
)
StringJoin[s1, s2]
-
Short syntax:
s1 <> s2
StringJoinStringJoin["ab", "cd", "e"] === "abcde"
"ab" <> "cd" <> "e" === "abcde"
Get Substring, by Position
StringTake[str, n]
-
first char to nth.
StringTake
StringTake["abcde", 3] === "abc"
StringTake[str, -n]
-
count from right, first char to nth.
StringTake["abcde", -3] === "cde"
StringTake[str, {n}]
-
nth char.
StringTake["abcde", {3}] === "c"
StringTake[str, {n, m}]
-
nth to mth chars.
StringTake["abcde", {2,4}] === "bcd"
StringTake[str, {spec1, spec2 etc}]
-
return a list of result, for each spec.
StringTake["abcde", {2, {2}, {2,4}}] === {"ab", "b", "bcd"}
StringTake[{str1, str2 etc}, spec]
-
return a list of result, for each string.
StringTake[{"abcde", "123456"}, 2] === {"ab", "12"} StringTake[{"abcde", "123456"}, {2}] === {"b", "2"} StringTake[{"abcde", "123456"}, {2,4}] === {"bcd", "234"}
StringTake[{"abcde", "123456"}, {2, {2}, {2,4}}] === {{"ab", "b", "bcd"}, {"12", "2", "234"}}
Get Substring by Pattern
StringCases
[see WolframLang: String Replace]
Insert into string
StringInsert
-
Insert by position
StringInsert
StringInsert[ "love cat", "I ", 1 ] === "I love cat"
Delete substring
StringDrop
- Delete parts by position. StringDrop
StringDelete
- Delete parts by String pattern (regex) . StringDelete
StringTrim
- Remove whitespace StringTrim
Format string
ToString
- Convert number or any expression to string. ToString
StringTemplate
- Template system with placeholders StringTemplate
String to list
StringSplit
-
split a string to a list of strings.
StringSplit
(* split by whitespace *) StringSplit[ "a b" ] === {"a", "b"}
(* split by comma *) StringSplit[ "a,b,c", "," ] === {"a", "b", "c"}
List to string
StringRiffle
-
List to string.
StringRiffle
StringRiffle[ {"a" , "b" , "c"}, " " ] === "a b c"
String to Number
ToExpression
-
String to number.
ToExpression
ToExpression[ "3" ] === 3 ToExpression[ "3.21" ] === 3.21
List All String Functions
Names["*String*"] (* or *) Information["*String*"]
- BooleanStrings
- ByteArrayToString
- DateString
- DisplayString
- DMSString
- EndOfString
- ExportString
- FrontEndResourceString
- FunctionCompileExportString
- ImportString
- InputString
- InputStringPacket
- InString
- IntegerString
- MissingString
- NumberString
- ReadString
- RepeatedString
- SearchQueryString
- SemanticImportString
- ShowStringCharacters
- SpokenString
- StartOfString
- String
- StringBreak
- StringByteCount
- StringCases
- StringContainsQ
- StringCount
- StringDelete
- StringDrop
- StringEndsQ
- StringExpression
- StringExtract
- StringForm
- StringFormat
- StringFormatQ
- StringFreeQ
- StringInsert
- StringJoin
- StringLength
- StringMatchQ
- StringPadLeft
- StringPadRight
- StringPart
- StringPartition
- StringPosition
- StringQ
- StringRepeat
- StringReplace
- StringReplaceList
- StringReplacePart
- StringReverse
- StringRiffle
- StringRotateLeft
- StringRotateRight
- StringSkeleton
- StringSplit
- StringStartsQ
- StringTake
- StringTemplate
- StringToByteArray
- StringToStream
- StringTrim
- TextString
- ToString
- WriteString
WolframLang: List Functions, Find Function