Text Functions
The text functions read a string by Unicode character, as size() counts it, so a character outside the Basic Multilingual Plane (an emoji, a letter of Deseret or Adlam, a CJK Extension B ideograph) is one character: text.capitalize(), text.decapitalize(), text.capitalizeAll() and text.decapitalizeAll() map its case, text.camelCase(), text.snakeCase() and text.upperCamelCase() take a letter outside the plane for a letter and not for a word break, text.replace() and text.split() with an empty search or delimiter cut between characters and never inside one, and text.random() draws whole characters. The openCypher ltrim(), rtrim(), btrim() and trim() with a set of characters to strip do the same. (Since v26.11.1, issues #10484 and #10485) Before, they worked on UTF-16 units and could return half of a character. text.split() keeps the empty pieces, as split() does. The distance and similarity functions (text.hammingDistance(), text.levenshteinDistance(), text.levenshteinSimilarity(), text.jaroWinklerDistance() and text.sorensenDiceSimilarity()) compare characters too (since v26.11.1, issue #10417): one emoji replaced by another is one edit, text.hammingDistance() compares the number of characters and not of UTF-16 units, the 10,000 character limit of text.levenshteinDistance() counts characters, and a bigram of text.sorensenDiceSimilarity() is never cut inside a character. The number for two strings is the one for the same two strings written with characters of the Basic Multilingual Plane.
|
text.byteCount()
Get the byte count of a string.
Syntax: text.byteCount(string)
Returns: Long - Number of bytes
APOC Compatible: apoc.text.byteCount
text.camelCase()
Convert a string to camelCase.
Syntax: text.camelCase(string)
Returns: String - camelCase string
APOC Compatible: apoc.text.camelCase
RETURN text.camelCase("hello world") AS result
// Returns: "helloWorld"
RETURN text.camelCase("hello_world") AS result
// Returns: "helloWorld"
text.capitalize()
Capitalize the first letter of a string.
Syntax: text.capitalize(string)
Returns: String - Capitalized string
APOC Compatible: apoc.text.capitalize
RETURN text.capitalize("hello") AS result
// Returns: "Hello"
text.capitalizeAll()
Capitalize the first letter of each word.
Syntax: text.capitalizeAll(string)
Returns: String - String with all words capitalized
APOC Compatible: apoc.text.capitalizeAll
RETURN text.capitalizeAll("hello world") AS result
// Returns: "Hello World"
text.charAt()
Get the character at a specific index.
Syntax: text.charAt(string, index)
Returns: String - Character at index
APOC Compatible: apoc.text.charAt
Positions and lengths count Unicode characters: a character outside the Basic Multilingual Plane, such as an emoji, is one character and is never cut in two. Before 26.11.1 (issue #10378) the count was in UTF-16 code units, so such a character counted 2 and text.charAt() could return half of it.
|
text.code()
Get the Unicode code point of a character.
Syntax: text.code(character)
Returns: Long - Unicode code point
APOC Compatible: apoc.text.code
text.decapitalize()
Decapitalize the first letter of a string.
Syntax: text.decapitalize(string)
Returns: String - Decapitalized string
APOC Compatible: apoc.text.decapitalize
text.decapitalizeAll()
Decapitalize the first letter of each word.
Syntax: text.decapitalizeAll(string)
Returns: String - String with all words decapitalized
APOC Compatible: apoc.text.decapitalizeAll
text.format()
Format a string using printf-style formatting. Number formatting (%f, %e, %d, etc.) is always locale-independent (e.g. . as decimal separator), regardless of the server’s configured locale.
Syntax: text.format(format, args…)
Returns: String - Formatted string
APOC Compatible: apoc.text.format
text.hammingDistance()
Calculate the Hamming distance between two strings of equal length. Returns the number of positions at which the corresponding characters differ.
Syntax: text.hammingDistance(string1, string2)
Returns: Long - Number of positions with different characters
APOC Compatible: apoc.text.hammingDistance
SELECT text.hammingDistance('karolin', 'kathrin') AS distance
-- Returns: 3
SELECT text.hammingDistance(name, 'John') AS dist FROM Person
RETURN text.hammingDistance("karolin", "kathrin") AS distance
// Returns: 3
text.hexValue()
Convert a number to its hexadecimal representation.
Syntax: text.hexValue(number)
Returns: String - Hexadecimal string
APOC Compatible: apoc.text.hexValue
text.indexOf()
Find the position of a substring within a string.
Syntax: text.indexOf(string, substring, [start])
Parameters:
| Parameter | Type | Description |
|---|---|---|
string |
String |
The string to search in |
substring |
String |
The substring to find |
start |
Integer |
Optional - Starting position (default: 0) |
Returns: Long - Position of substring, or -1 if not found
APOC Compatible: apoc.text.indexOf
Positions and lengths count Unicode characters: a character outside the Basic Multilingual Plane, such as an emoji, is one character and is never cut in two. Before 26.11.1 (issue #10378) the count was in UTF-16 code units, so such a character counted 2 and text.charAt() could return half of it.
|
RETURN text.indexOf("hello world", "world") AS pos
// Returns: 6
RETURN text.indexOf("hello hello", "hello", 1) AS pos
// Returns: 6
text.jaroWinklerDistance()
Calculate the Jaro-Winkler similarity between two strings. Returns a value between 0.0 (completely different) and 1.0 (identical). This metric is especially effective for detecting typos and misspellings because it gives extra weight to matching prefixes.
Syntax: text.jaroWinklerDistance(string1, string2)
Returns: Double - Similarity score (0.0 to 1.0)
APOC Compatible: apoc.text.jaroWinklerDistance
-- Find similar names using fuzzy matching
SELECT name, text.jaroWinklerDistance(name, 'John') AS score
FROM Person
WHERE text.jaroWinklerDistance(name, 'John') > 0.85
ORDER BY score DESC
-- Compare two literal strings
SELECT text.jaroWinklerDistance('hello', 'helo') AS score
-- Returns: ~0.953
RETURN text.jaroWinklerDistance("hello", "helo") AS score
// Returns: ~0.953
MATCH (p:Person)
WHERE text.jaroWinklerDistance(p.name, "John") > 0.85
RETURN p.name, text.jaroWinklerDistance(p.name, "John") AS score
ORDER BY score DESC
text.join()
Join a list of strings with a delimiter.
Syntax: text.join(list, delimiter)
Parameters:
| Parameter | Type | Description |
|---|---|---|
list |
List |
List of strings to join |
delimiter |
String |
String to insert between elements |
Returns: String - Joined string
APOC Compatible: apoc.text.join
RETURN text.join(["a", "b", "c"], ",") AS result
// Returns: "a,b,c"
text.levenshteinDistance()
Calculate the Levenshtein (edit) distance between two strings. Returns the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.
Syntax: text.levenshteinDistance(string1, string2)
Returns: Long - Number of edits required
Each argument is limited to 10,000 characters. A longer string is rejected with String length exceeds maximum
allowed, because the computation cost grows with the two lengths multiplied together.
|
APOC Compatible: apoc.text.levenshteinDistance
SELECT text.levenshteinDistance('kitten', 'sitting') AS distance
-- Returns: 3
SELECT name, text.levenshteinDistance(name, 'John') AS edits
FROM Person
WHERE text.levenshteinDistance(name, 'John') <= 2
RETURN text.levenshteinDistance("kitten", "sitting") AS distance
// Returns: 3
text.levenshteinSimilarity()
Calculate the normalized Levenshtein similarity (0-1) between two strings. This is computed as 1.0 - (editDistance / maxLength), providing a score where 1.0 means identical strings.
Syntax: text.levenshteinSimilarity(string1, string2)
Returns: Double - Similarity score (0.0 to 1.0)
APOC Compatible: apoc.text.levenshteinSimilarity
SELECT text.levenshteinSimilarity('hello', 'hallo') AS similarity
-- Returns: 0.8
RETURN text.levenshteinSimilarity("hello", "hallo") AS similarity
// Returns: 0.8
text.lpad()
Left-pad a string to a specified length.
Syntax: text.lpad(string, length, padChar)
Returns: String - Padded string
APOC Compatible: apoc.text.lpad
| The length is counted in Unicode characters, and a pad character outside the Basic Multilingual Plane is one character. Before 26.11.1 (issue #10378) it was counted in UTF-16 code units, so a string holding an emoji measured one more than its characters and was not padded to its width. |
RETURN text.lpad("42", 5, "0") AS result
// Returns: "00042"
text.random()
Generate a random string.
Syntax: text.random(length, [chars])
Returns: String - Random string
APOC Compatible: apoc.text.random
text.regexReplace()
Replace all matches of a regular expression.
Syntax: text.regexReplace(string, regex, replacement)
Returns: String - String with replacements made
APOC Compatible: apoc.text.regexReplace
RETURN text.regexReplace("hello123world", "[0-9]+", "-") AS result
// Returns: "hello-world"
text.replace()
Replace all occurrences of a substring.
Syntax: text.replace(string, search, replacement)
Returns: String - String with replacements made
APOC Compatible: apoc.text.replace
RETURN text.replace("hello world", "world", "universe") AS result
// Returns: "hello universe"
text.rpad()
Right-pad a string to a specified length.
Syntax: text.rpad(string, length, padChar)
Returns: String - Padded string
APOC Compatible: apoc.text.rpad
| The length is counted in Unicode characters, and a pad character outside the Basic Multilingual Plane is one character. Before 26.11.1 (issue #10378) it was counted in UTF-16 code units, so a string holding an emoji measured one more than its characters and was not padded to its width. |
RETURN text.rpad("42", 5, "0") AS result
// Returns: "42000"
text.slug()
Create a URL-friendly slug from a string.
Syntax: text.slug(string, [delimiter])
Parameters:
| Parameter | Type | Description |
|---|---|---|
string |
String |
The string to convert |
delimiter |
String |
Optional - Character to use as word separator (default: "-") |
Returns: String - URL-friendly slug
APOC Compatible: apoc.text.slug
RETURN text.slug("Hello World!") AS result
// Returns: "hello-world"
RETURN text.slug("Hello World!", "_") AS result
// Returns: "hello_world"
text.snakeCase()
Convert a string to snake_case.
Syntax: text.snakeCase(string)
Returns: String - snake_case string
APOC Compatible: apoc.text.snakeCase
RETURN text.snakeCase("helloWorld") AS result
// Returns: "hello_world"
text.sorensenDiceSimilarity()
Calculate the Sorensen-Dice similarity coefficient between two strings based on bigram (character pair) overlap. Returns a value between 0.0 (no common bigrams) and 1.0 (identical). Useful for comparing short strings and detecting near-duplicates.
Syntax: text.sorensenDiceSimilarity(string1, string2)
Returns: Double - Similarity score (0.0 to 1.0)
APOC Compatible: apoc.text.sorensenDiceSimilarity
SELECT text.sorensenDiceSimilarity('night', 'nacht') AS score
RETURN text.sorensenDiceSimilarity("night", "nacht") AS score