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
concatformatmapconcatbyte-to-string
Convert String and Number
string-to-numbernumber-to-stringformat
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-search-
(string-search search Str &optional START-POS)Find search in Str. If found, return the index of first occurrence, else return
nil.(string-search "ab" "ttabtt" ) ;; 2 (string-search "ab" "ttt" ) ;; nil
string-match-
(string-match REGEXP STRING &optional START)Return the index of beginning of first match in STRING. Return
nilif no match.(let ((case-fold-search t)) (string-match "3" "xx3x")) ;; 2
Get Regex Captured String
match-string
Replace in String
string-replacereplace-regexp-in-string
Trim String
string-trim-leftstring-trim-rightstring-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-prefixstring-remove-suffixstring-pad
Misc String Functions
stringp→ is stringstring-or-null-p
make-stringsubstring-no-properties- split-string-default-separators → variable
store-substring→ modify stringclear-string
assoc-string→ Elisp: Association List
Letter Case
downcaseupcasecapitalizeupcase-initials
Case Table
case-table-pset-standard-case-tablestandard-case-tablecurrent-case-tableset-case-tableset-case-syntax-pairset-case-syntax-delimsset-case-syntaxwith-case-table- ascii-case-table
describe-buffer-case-table