Emacs Lisp: String Functions

By Xah Lee. Date: . Last updated: .

Here is a complete list of string functions.

Basic String Functions

(length SEQUENCE)
Return the length of vector, list or string SEQUENCE.
(length "abc")
;; 3
(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 &rest SEQUENCES)
Concatenate all the arguments and make the result a string.
(concat "some" "thing")
(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


[see Emacs Lisp: Regex Functions]

Get Regex Captured String


[see Emacs Lisp: Match Data (Regex Result)]

Regex Replace in String


[see Emacs Lisp: Regex Functions]

Trim String

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)

Strings and Characters (ELISP Manual)

String Functions Reference

Here's a complete list of string functions for reference.

Predicates for Strings (ELISP Manual)

Creating Strings (ELISP Manual)

Modifying Strings (ELISP Manual)

Text Comparison (ELISP Manual)

Text Comparison (ELISP Manual)

Case Conversion (ELISP Manual)

Case Tables (ELISP Manual)

Emacs Lisp String