Elisp: String Functions
Length, Substring
length
-
(length SEQUENCE)
Return the length of a 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, and FROM is 0. If negative, count from right.
(substring "abc123" 0 3) ;; "abc"
Join Strings, Convert to String
concat
format
mapconcat
byte-to-string
Convert String and Number
string-to-number
number-to-string
format
Convert String to Codepoints
vconcat
→ string to vector of codepoints.append
→ string to list of codepoints.
Split String (String to List)
split-string
-
(split-string STRING &optional SEPARATORS OMIT-NULLS TRIM)
- Split STRING
- Return a list.
- SEPARATORS is a Elisp: Regular Expression
;; split string into parts, return a list (split-string "xy_007_cat" "_")
Buffer Text to String
String to Buffer
Check If Contains a Pattern, Find Index of Substring
string-match
-
(string-match REGEXP STRING &optional START)
Return the index of beginning of first match in STRING. Return
nil
if no match.(let ((case-fold-search t)) (string-match "3" "xx3x")) ;; 2
Get Regex Captured String
match-string
Replace in String
string-replace
replace-regexp-in-string
Trim String
string-trim-left
string-trim-right
string-trim
These are new in
Emacs 24.4 (date 2014-10)
.
Before
Emacs 28 (date 2022)
,
you need to first load
(require 'subr-x)
.
String Comparison, Equality Test
Character and String
Other String Functions
To use the following, you may need to first load the lib:
(require 'subr-x)
string-blank-p
→ is empty or whitespace.string-empty-p
→ is empty.string-join
→ join with separators.string-reverse
(obsolete. usereverse
)string-remove-prefix
string-remove-suffix
string-pad
Misc String Functions
stringp
→ is stringstring-or-null-p
make-string
substring-no-properties
- split-string-default-separators → variable
store-substring
→ modify stringclear-string
assoc-string
Letter Case
downcase
upcase
capitalize
upcase-initials
Case Table
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