Skip to main content

string Domain

The string domain maps domain keywords to underlying faker implementations.

Faker Documentation

Methods

string.alpha

Generating a string consisting of letters in the English alphabet.

ArgTypeRequiredDescription
lengthnumbernoDesired length of the generated value.
casingupper|lower|mixednoThe casing of the characters.
excludearraynoAn array with characters which should be excluded in the generated string.

Examples:

Shows string.alpha with all optional params omitted.

string.alpha()

Returns: v

Shows string.alpha generating a fixed-length alphabetic value.

string.alpha(length=5)

Returns: vLaph

Shows string.alpha using only the casing option.

string.alpha(casing="upper")

Returns: K

Shows string.alpha with explicit uppercase output.

string.alpha(length=5, casing="upper")

Returns: KSAHD

Shows string.alpha excluding specific characters without setting length or casing.

string.alpha(exclude=["A","B","C"])

Returns: u

Shows string.alpha excluding specific characters from the candidate set.

string.alpha(length=5, casing="upper", exclude=["A","B","C"])

Returns: MTDJG

string.alphanumeric

Generating a string consisting of alpha characters and digits.

ArgTypeRequiredDescription
lengthnumbernoDesired length of the generated value.
casingupper|lower|mixednoThe casing of the characters.
excludearraynoAn array of characters and digits which should be excluded in the generated string.

Examples:

Shows string.alphanumeric when optional params are omitted.

string.alphanumeric()

Returns: p

Shows string.alphanumeric using length.

string.alphanumeric(length=5)

Returns: pI0i9

Shows string.alphanumeric using casing.

string.alphanumeric(casing="upper")

Returns: F

Shows string.alphanumeric using exclude.

string.alphanumeric(exclude=["A","B","C"])

Returns: o

string.binary

Returns a binary string.

ArgTypeRequiredDescription
lengthnumbernoThe length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
prefixstringnoPrefix for the generated number.

Examples:

Shows string.binary when optional params are omitted.

string.binary()

Returns: 0b0

Shows string.binary using length.

string.binary(length=5)

Returns: 0b01000

Shows string.binary using prefix.

string.binary(prefix="PRE-")

Returns: PRE-0

string.counterString

Generates a counterstring for a random length between min and max (or fixed length when only one value is provided). Defaults to min=1 and max=25 when omitted.

  • Canonical: awd.domain.string.counterString
ArgTypeRequiredDescription
minintegernoMinimum counterstring length (integer). If max is omitted and min is provided, min is also used as max. Defaults to 1 when omitted. Non-integer values throw an exception.
maxintegernoMaximum counterstring length (integer). If less than min, values are swapped. Defaults to 25 when omitted. Non-integer values throw an exception.
delimiterstringnoDelimiter character used between position markers. Defaults to "*".

Examples:

Shows string.counterString default from 1 to 25 chars.

string.counterString()

Returns: *3*5*7*10*13*

Shows string.counterString with a fixed length of 15 chars.

string.counterString(min=15)

Returns: *3*5*7*9*12*15*

Shows string.counterString with a length between 5 and 12 chars.

string.counterString(min=5, max=12)

Returns: *3*5*7*9*

Shows string.counterString with a fixed length of 12 chars and a custom delimiter.

string.counterString(min=12, max=12, delimiter="#")

Returns: #3#5#7#9#12#

Shows string.counterString with a length between 1 and 10 chars.

string.counterString(max=10, min=1)

Returns: 2*4*6*

Shows string.counterString with a length between 1 and 12 chars.

string.counterString(max=12)

Returns: *3*5*7*

Shows string.counterString using a custom delimiter and a length between 1 and 25 chars.

string.counterString(delimiter="#")

Returns: #3#5#7#10#13#

string.fromCharacters

Generates a string from the given characters.

ArgTypeRequiredDescription
charactersstring|arrayyesCharacter set (string or array) used when generating output.
lengthintegernoDesired length of the generated value.

Examples:

Shows string.fromCharacters with only the required characters argument.

string.fromCharacters(characters="ABC123")

Returns: C

Shows string.fromCharacters in use.

string.fromCharacters(characters=["A", "B", "C"], length=4)

Returns: BCAA

Shows string.fromCharacters using length.

string.fromCharacters(characters="ABC123", length=4)

Returns: C2AB

string.hexadecimal

Returns a hexadecimal string.

ArgTypeRequiredDescription
casingupper|lower|mixednoCasing of the generated number.
lengthnumbernoThe length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
prefixstringnoPrefix for the generated number.

Examples:

Shows string.hexadecimal when optional params are omitted.

string.hexadecimal()

Returns: 0x9

Shows string.hexadecimal using casing.

string.hexadecimal(casing="upper")

Returns: 0x9

Shows string.hexadecimal using length.

string.hexadecimal(length=5)

Returns: 0x9f063

Shows string.hexadecimal using prefix.

string.hexadecimal(prefix="PRE-")

Returns: PRE-9

string.nanoid

Generates a Nano ID.

ArgTypeRequiredDescription
lengthnumbernoExact number of characters to generate.

Examples:

Shows string.nanoid when optional params are omitted.

string.nanoid()

Returns: Ii5lxGSFycYGT2SqxjPK-

Shows string.nanoid using length.

string.nanoid(length=5)

Returns: Ii5lx

string.numeric

Generates a given length string of digits.

ArgTypeRequiredDescription
lengthnumbernoDesired length of the generated value.
allowLeadingZerosbooleannoWhether leading zeros are allowed or not.
excludearraynoAn array of digits which should be excluded in the generated string.

Examples:

Shows string.numeric when optional params are omitted.

string.numeric()

Returns: 4

Shows string.numeric using length.

string.numeric(length=5)

Returns: 47031

Shows string.numeric using allowLeadingZeros.

string.numeric(allowLeadingZeros=true)

Returns: 4

Shows string.numeric using exclude.

string.numeric(exclude=["A","B","C"])

Returns: 4

string.octal

Returns an octal string.

ArgTypeRequiredDescription
lengthnumbernoThe length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
prefixstringnoPrefix for the generated number.

Examples:

Shows string.octal when optional params are omitted.

string.octal()

Returns: 0o3

Shows string.octal using length.

string.octal(length=5)

Returns: 0o35021

Shows string.octal using prefix.

string.octal(prefix="PRE-")

Returns: PRE-3

string.sample

Returns a string containing UTF-16 chars between 33 and 125 (! to }).

ArgTypeRequiredDescription
lengthnumbernoExact number of characters to generate.

Examples:

Shows string.sample when optional params are omitted.

string.sample()

Returns: Gc!=.)2AES

Shows string.sample using length.

string.sample(length=5)

Returns: Gc!=.

string.symbol

Returns a string containing only ASCII symbol characters such as !, ", #, $, %, &, (, ), *, +, -, /, :, ;, <, =, >, ?, @, [, , ], ^, _, `, {, |, }, and ~.

ArgTypeRequiredDescription
lengthnumbernoExact number of characters to generate.

Examples:

Shows string.symbol when optional params are omitted.

string.symbol()

Returns: .

Shows string.symbol using length.

string.symbol(length=5)

Returns: .\!*%

string.ulid

Returns a ULID (Universally Unique Lexicographically Sortable Identifier).

ArgTypeRequiredDescription
refDatenumbernoThe date to use as reference point for the newly generated ULID encoded timestamp. The encoded timestamp is represented by the first 10 characters of the result.

Examples:

Shows string.ulid when optional params are omitted.

string.ulid()

Returns: 01KVDQ3AJ0DQ09425BCHDN6W0N

Shows string.ulid using refDate.

string.ulid(refDate=1718755200000)

Returns: 01J0PWP300DQ09425BCHDN6W0N

string.uuid

Returns a UUID (Universally Unique Identifier).

ArgTypeRequiredDescription
version4|7noThe specific UUID version to use. If refDate is supplied and version is omitted, version 7 is used automatically.
refDatestring|number|datenoThe timestamp to encode into the UUID. This is only valid for UUID v7. If refDate is supplied and version is omitted, version 7 is used automatically. Providing refDate with version 4 is invalid.

Examples:

Shows string.uuid when optional params are omitted.

string.uuid()

Returns: 6b042125-686a-43e0-8a68-23cf5bee102e

Shows string.uuid using version.

string.uuid(version=7)

Returns: 019edb71-aa40-76b0-8421-25686a3e0a68

Shows string.uuid using refDate.

string.uuid(refDate="2026-06-18T00:00:00.000Z")

Returns: 019ed807-0800-76b0-8421-25686a3e0a68