Text Functions
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
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.
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
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.96
RETURN text.jaroWinklerDistance("hello", "helo") AS score
// Returns: ~0.96
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
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
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
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