Emacs Lisp: String Functions
Here is a complete list of string functions.
Basic String Functions
length
-
(length SEQUENCE)
Return the length of vector, list or string SEQUENCE.(length "abc") ;; 3
substring
-
(substring STRING &optional FROM TO)
return a substring from position FROM to TO. Position start at 0. By default, TO is to end of string, if omitted. FROM is 0. If negative, count from right.(substring "abc123" 0 3) ;; "abc"
concat
-
(concat &rest SEQUENCES)
Concatenate all the arguments and make the result a string.(concat "some" "thing")
split-string
-
(split-string STRING &optional SEPARATORS OMIT-NULLS TRIM)
Split STRING into substrings bounded by matches for SEPARATORS.;; split string into parts, returns a list (split-string "xy_007_cat" "_")
String To/From Number
Buffer Text to String
String to Buffer
Match String by Regex
string-match
Get Regex Captured String
match-string
Regex Replace in String
replace-regexp-in-string
Trim String
string-trim-left
string-trim-right
string-trim
These are new in
Emacs 24.4 (Released 2014-10)
.
Before
Emacs 28 (Released 2022-04)
,
you need to first load
(require 'subr-x)
.
[see Emacs Version History]
Other String Functions
To use the following, you need to first load a lib:
(require 'subr-x)
string-blank-p
string-empty-p
string-join
string-reverse
string-remove-prefix
string-remove-suffix
string-pad
String Functions Reference
Here's a complete list of string functions for reference.
stringp
string-or-null-p
char-or-string-p
Predicates for Strings (ELISP Manual)
make-string
string
→ chars to stringsubstring-no-properties
concat
- split-string-default-separators
Creating Strings (ELISP Manual)
store-substring
→ modify stringclear-string
Modifying Strings (ELISP Manual)
char-equal
string-equal
string-collate-equalp
string-greaterp
string-collate-lessp
string-version-lessp
string-prefix-p
string-suffix-p
compare-strings
string-distance
assoc-string
Text Comparison (ELISP Manual)
number-to-string
string-to-number
char-to-string
string-to-char
concat
vconcat
→ string into a vectorappend
→ string into a listbyte-to-string
Text Comparison (ELISP Manual)
downcase
upcase
capitalize
upcase-initials
Case Conversion (ELISP Manual)
case-table-p
set-standard-case-table
standard-case-table
current-case-table
set-case-table
set-case-syntax-pair
set-case-syntax-delims
set-case-syntax
with-case-table
- ascii-case-table
describe-buffer-case-table