nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
Character Strings and Text (strfun)

Text composition, formatted string output (sprintf), search, regular expressions, and type conversions. More...

Files

file  strfun.hpp
 String, character vector, and regular expression operations.

Functions

Value nk::builtin::num2str (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Formats numeric array into character vector (num2str(x)).
Value nk::builtin::num2str (const Value &x, int N, std::pmr::memory_resource *mr=nullptr)
 Formats numeric array into character vector with specified precision digits (num2str(x, N)).
Value nk::builtin::num2str (const Value &x, const std::string &fmt, std::pmr::memory_resource *mr=nullptr)
 Formats numeric array into character vector with format specification (num2str(x, fmt)).
Value nk::builtin::int2str (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Formats integer into character vector (int2str(x)).
Value nk::builtin::mat2str (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Formats matrix into MATLAB syntax string (mat2str(x)).
Value nk::builtin::mat2str (const Value &x, int precision, std::pmr::memory_resource *mr=nullptr)
 Formats matrix into MATLAB syntax string with precision (mat2str(x, precision)).
Value nk::builtin::str2num (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Converts string representation to numeric matrix (str2num(s)).
Value nk::builtin::str2double (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Converts text to double precision numeric values (str2double(s)).
Value nk::builtin::char_array (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Converts input to character array (char(x)).
Value nk::builtin::toChar (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Alias for char_array conversion (char(x)).
Value nk::builtin::string_array (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Converts input to string array (string(x)).
Value nk::builtin::toString (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Alias for string_array conversion (string(x)).
Value nk::builtin::blanks (size_t n, std::pmr::memory_resource *mr=nullptr)
 Creates character vector of blank spaces (blanks(n)).
Value nk::builtin::newline (std::pmr::memory_resource *mr=nullptr)
 Creates newline character string (newline).
Value nk::builtin::newlineFn (std::pmr::memory_resource *mr=nullptr)
 Generates newline character as string Value.
Value nk::builtin::strcmp (const Value &s1, const Value &s2, std::pmr::memory_resource *mr=nullptr)
 Compares strings for exact equality (case-sensitive) (strcmp(s1, s2)).
Value nk::builtin::strncmp (const Value &s1, const Value &s2, size_t n, std::pmr::memory_resource *mr=nullptr)
 Compares first n characters of strings (case-sensitive) (strncmp(s1, s2, n)).
Value nk::builtin::strcmpi (const Value &s1, const Value &s2, std::pmr::memory_resource *mr=nullptr)
 Compares strings for equality ignoring case (strcmpi(s1, s2)).
Value nk::builtin::strncmpi (const Value &s1, const Value &s2, size_t n, std::pmr::memory_resource *mr=nullptr)
 Compares first n characters of strings ignoring case (strncmpi(s1, s2, n)).
Value nk::builtin::matches (const Value &str, const Value &pat, std::pmr::memory_resource *mr=nullptr)
 Tests if strings match pattern (matches(str, pat)).
Value nk::builtin::upper (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Converts string to uppercase (upper(s)).
Value nk::builtin::lower (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Converts string to lowercase (lower(s)).
Value nk::builtin::strtrim (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Removes leading and trailing whitespace (strtrim(s)).
Value nk::builtin::deblank (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Removes trailing whitespace (deblank(s)).
Value nk::builtin::strip (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Strips leading and trailing whitespace from string array (strip(s)).
Value nk::builtin::strip (const Value &s, const Value &side, const Value &ch, std::pmr::memory_resource *mr=nullptr)
 Strips specified characters from side of string array (strip(s, side, ch)).
Value nk::builtin::strcat (Span< const Value > args, std::pmr::memory_resource *mr=nullptr)
 Concatenates strings horizontally (strcat(s1, s2, ...)).
Value nk::builtin::strjoin (const Value &c, const std::string &delim=" ", std::pmr::memory_resource *mr=nullptr)
 Joins string array or cell array of strings with delimiter (strjoin(c, delim)).
Value nk::builtin::strjoin (const Value &arr, const Value &delim, std::pmr::memory_resource *mr=nullptr)
 Joins string array with Value delimiter (strjoin(arr, delim)).
Value nk::builtin::join (const Value &arr, const Value &delim=Value::Empty, std::pmr::memory_resource *mr=nullptr)
 Combines elements of string array into single string (join(arr, delim)).
Value nk::builtin::append (Span< const Value > parts, std::pmr::memory_resource *mr=nullptr)
 Appends multiple strings element-wise (append(s1, s2, ...)).
Value nk::builtin::strsplit (const Value &s, const std::string &delim=" ", std::pmr::memory_resource *mr=nullptr)
 Splits string by delimiter string (strsplit(s, delim)).
Value nk::builtin::strsplit (const Value &s, const Value &delim, std::pmr::memory_resource *mr=nullptr)
 Splits string by Value delimiter (strsplit(s, delim)).
Value nk::builtin::strsplit (const Value &s, std::pmr::memory_resource *mr)
 Splits string by whitespace (strsplit(s)).
Value nk::builtin::split (const Value &s, const Value &delim=Value::Empty, std::pmr::memory_resource *mr=nullptr)
 Splits string array elements by delimiter (split(s, delim)).
Value nk::builtin::splitlines (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Splits string into separate lines (splitlines(s)).
Value nk::builtin::strfind (const Value &text, const Value &pattern, std::pmr::memory_resource *mr=nullptr)
 Finds occurrences of substring within string (strfind(text, pattern)).
Value nk::builtin::strrep (const Value &orig, const Value &oldStr, const Value &newStr, std::pmr::memory_resource *mr=nullptr)
 Replaces occurrences of substring within string (strrep(orig, old, new)).
Value nk::builtin::contains (const Value &str, const Value &pat, bool ignoreCase=false, std::pmr::memory_resource *mr=nullptr)
 Checks if string contains pattern (contains(str, pat)).
Value nk::builtin::startsWith (const Value &str, const Value &pat, bool ignoreCase=false, std::pmr::memory_resource *mr=nullptr)
 Checks if string starts with pattern (startsWith(str, pat)).
Value nk::builtin::endsWith (const Value &str, const Value &pat, bool ignoreCase=false, std::pmr::memory_resource *mr=nullptr)
 Checks if string ends with pattern (endsWith(str, pat)).
Value nk::builtin::strlength (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Returns number of characters in each string element (strlength(s)).
Value nk::builtin::count (const Value &str, const Value &pat, std::pmr::memory_resource *mr=nullptr)
 Counts occurrences of pattern in string (count(str, pat)).
Value nk::builtin::reverse (const Value &str, std::pmr::memory_resource *mr=nullptr)
 Reverses characters in string (reverse(str)).
Value nk::builtin::erase (const Value &s, const Value &pat, std::pmr::memory_resource *mr=nullptr)
 Erases occurrences of substring pattern from string (erase(s, pat)).
Value nk::builtin::replace (const Value &s, const Value &oldPat, const Value &newPat, std::pmr::memory_resource *mr=nullptr)
 Replaces substring pattern with new pattern in string array (replace(s, oldPat, newPat)).
Value nk::builtin::replaceBetween (const Value &s, const Value &start, const Value &end, const Value &newText, std::pmr::memory_resource *mr=nullptr)
 Replaces text between specified start and end boundaries (replaceBetween(s, start, end, newText)).
Value nk::builtin::extractAfter (const Value &s, const Value &p, std::pmr::memory_resource *mr=nullptr)
 Extracts substrings after specified pattern or position (extractAfter(s, p)).
Value nk::builtin::extractBefore (const Value &s, const Value &p, std::pmr::memory_resource *mr=nullptr)
 Extracts substrings before specified pattern or position (extractBefore(s, p)).
Value nk::builtin::extractBetween (const Value &s, const Value &start, const Value &end, std::pmr::memory_resource *mr=nullptr)
 Extracts substrings between specified boundaries (extractBetween(s, start, end)).
Value nk::builtin::insertAfter (const Value &s, const Value &p, const Value &newText, std::pmr::memory_resource *mr=nullptr)
 Inserts text after specified position or pattern (insertAfter(s, p, newText)).
Value nk::builtin::insertBefore (const Value &s, const Value &p, const Value &newText, std::pmr::memory_resource *mr=nullptr)
 Inserts text before specified position or pattern (insertBefore(s, p, newText)).
Value nk::builtin::eraseBetween (const Value &s, const Value &start, const Value &end, std::pmr::memory_resource *mr=nullptr)
 Erases text between specified boundaries (eraseBetween(s, start, end)).
Value nk::builtin::extract (const Value &s, const Value &pat, std::pmr::memory_resource *mr=nullptr)
 Extracts substring matching pattern (extract(s, pat)).
Value nk::builtin::pad (const Value &s, size_t n, const Value &side=Value(), const Value &padChar=Value(), std::pmr::memory_resource *mr=nullptr)
 Pads string to fixed length (pad(s, n, side, padChar)).
Value nk::builtin::strjust (const Value &M, const std::string &side="left", std::pmr::memory_resource *mr=nullptr)
 Justifies character matrix (strjust(M, side)).
Value nk::builtin::isletter (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Tests if characters are letters (isletter(s)).
Value nk::builtin::isspace (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Tests if characters are whitespace (isspace(s)).
Value nk::builtin::isspaceFn (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Tests if characters are whitespace (internal helper returning Value).
Value nk::builtin::isstrprop (const Value &s, const std::string &category, std::pmr::memory_resource *mr=nullptr)
 Tests if characters have specified string property (isstrprop(s, category)).
Value nk::builtin::isstrprop (const Value &s, const Value &category, std::pmr::memory_resource *mr=nullptr)
 Tests if characters have specified string property via Value category (isstrprop(s, category)).
Value nk::builtin::isstringscalar (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Tests if input is a scalar string (isstringscalar(s)).
Value nk::builtin::validatestring (const Value &str, const Value &validStrings, std::pmr::memory_resource *mr=nullptr)
 Validates text against list of valid strings (validatestring(str, validStrings)).
Value nk::builtin::convertCharsToStrings (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Converts character arrays in input to string arrays (convertCharsToStrings(x)).
Value nk::builtin::convertStringsToChars (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Converts string arrays in input to character vectors (convertStringsToChars(x)).
Value nk::builtin::convertContainedStringsToChars (const Value &v, std::pmr::memory_resource *mr=nullptr)
 Recursively converts all contained strings in cells/structs to character vectors.
Value nk::builtin::stringsND (Span< const size_t > dims, std::pmr::memory_resource *mr=nullptr)
 Constructs an N-dimensional array of empty strings.
Value nk::builtin::dec2bin (const Value &d, int minDigits=0, std::pmr::memory_resource *mr=nullptr)
 Decimal to binary string (dec2bin(d, minDigits)).
Value nk::builtin::dec2hex (const Value &d, int minDigits=0, std::pmr::memory_resource *mr=nullptr)
 Decimal to hexadecimal string (dec2hex(d, minDigits)).
Value nk::builtin::dec2base (const Value &d, int base, int minDigits=0, std::pmr::memory_resource *mr=nullptr)
 Decimal to base-N string (dec2base(d, base, minDigits)).
Value nk::builtin::base2dec (const Value &s, int base, std::pmr::memory_resource *mr=nullptr)
 Base-N string to decimal (base2dec(s, base)).
Value nk::builtin::bin2dec (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Binary string to decimal (bin2dec(s)).
Value nk::builtin::hex2dec (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Hexadecimal string to decimal (hex2dec(s)).
Value nk::builtin::hex2num (const Value &s, std::pmr::memory_resource *mr=nullptr)
 Converts 16-character hexadecimal string to IEEE double-precision floating-point number (hex2num(s)).
Value nk::builtin::num2hex (const Value &x, std::pmr::memory_resource *mr=nullptr)
 Converts double-precision floating-point number to 16-character hexadecimal string (num2hex(x)).
Value nk::builtin::rat (const Value &x, double tol=0.0, std::pmr::memory_resource *mr=nullptr)
 Rational approximation as fraction / continued fraction (rat(x, tol)).
Value nk::builtin::rats (const Value &x, int len=13, std::pmr::memory_resource *mr=nullptr)
 Formats numbers as rational string representations (rats(x, len)).
std::pair< Value, Value > nk::builtin::strtok (const Value &str, const std::string &delim=" \t\n\r", std::pmr::memory_resource *mr=nullptr)
 Extracts first token from character vector up to delimiter ([token, rem] = strtok(str, delim)).
Value nk::builtin::regexp (const Value &str, const Value &pat, std::pmr::memory_resource *mr=nullptr)
 Regular expression matching (regexp(str, pat)).
Value nk::builtin::regexpi (const Value &str, const Value &pat, std::pmr::memory_resource *mr=nullptr)
 Case-insensitive regular expression matching (regexpi(str, pat)).
Value nk::builtin::regexpFind (const Value &s, const Value &pat, const std::string &option, bool ignoreCase, std::pmr::memory_resource *mr=nullptr)
 Regular expression search helper.
Value nk::builtin::regexpFindOnce (const Value &s, const Value &pat, const std::string &option, bool ignoreCase, std::pmr::memory_resource *mr=nullptr)
 Regular expression search once helper.
Value nk::builtin::regexprep (const Value &str, const Value &pat, const Value &rep, bool ignoreCase=false, bool once=false, std::pmr::memory_resource *mr=nullptr)
 Regular expression replacement (regexprep(str, pat, rep, ignoreCase, once)).
Value nk::builtin::regexptranslate (const std::string &type, const std::string &str, std::pmr::memory_resource *mr=nullptr)
 Translates wildcard strings to regular expressions (regexptranslate(type, str)).
Value nk::builtin::regexptranslate (const std::string &type, const Value &str, std::pmr::memory_resource *mr=nullptr)
 Translates wildcard Value to regular expression (regexptranslate(type, str)).
Value nk::builtin::compose (const Value &fmt, const Value &x, std::pmr::memory_resource *mr=nullptr)
 Formats data into string array (compose(fmt, x)).
std::string nk::builtin::formatOnce (const std::string &fmt, Span< const Value > args, size_t argStart=0, bool literalWhenShort=false)
 Formats single pass of format specification.
std::string nk::builtin::formatCyclic (const std::string &fmt, Span< const Value > args, size_t argStart=0, std::pmr::memory_resource *mr=nullptr)
 Formats cyclic repetition of format specification across array elements.
size_t nk::builtin::countFormatSpecs (const std::string &fmt)
 Counts number of conversion specifiers in format string.

Detailed Description

Text composition, formatted string output (sprintf), search, regular expressions, and type conversions.

Function Documentation

◆ append()

Value nk::builtin::append ( Span< const Value > parts,
std::pmr::memory_resource * mr = nullptr )

Appends multiple strings element-wise (append(s1, s2, ...)).

Parameters
partsSpan of input string arrays.
mrMemory resource.
Returns
Element-wise concatenated string array.

◆ base2dec()

Value nk::builtin::base2dec ( const Value & s,
int base,
std::pmr::memory_resource * mr = nullptr )

Base-N string to decimal (base2dec(s, base)).

Parameters
sBase-N text.
baseRadix base (2 to 36).
mrMemory resource.
Returns
Decimal double.
See also
dec2base

◆ bin2dec()

Value nk::builtin::bin2dec ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Binary string to decimal (bin2dec(s)).

Parameters
sBinary text.
mrMemory resource.
Returns
Decimal value.
See also
dec2bin

◆ blanks()

Value nk::builtin::blanks ( size_t n,
std::pmr::memory_resource * mr = nullptr )

Creates character vector of blank spaces (blanks(n)).

Parameters
nNumber of spaces.
mrMemory resource.
Returns
1 x n character vector containing ASCII space characters.

◆ char_array()

Value nk::builtin::char_array ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Converts input to character array (char(x)).

Parameters
xInput value (numeric array of codes, cell of strings, etc.).
mrMemory resource.
Returns
Character array.
See also
string_array, toChar

◆ compose()

Value nk::builtin::compose ( const Value & fmt,
const Value & x,
std::pmr::memory_resource * mr = nullptr )

Formats data into string array (compose(fmt, x)).

Parameters
fmtFormat string.
xInput arguments.
mrMemory resource.
Returns
Formatted string array.

◆ contains()

Value nk::builtin::contains ( const Value & str,
const Value & pat,
bool ignoreCase = false,
std::pmr::memory_resource * mr = nullptr )

Checks if string contains pattern (contains(str, pat)).

Parameters
strText to search.
patSubstring pattern.
ignoreCaseCase-insensitive flag.
mrMemory resource.
Returns
Logical scalar or array.
See also
startsWith, endsWith, matches

◆ convertCharsToStrings()

Value nk::builtin::convertCharsToStrings ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Converts character arrays in input to string arrays (convertCharsToStrings(x)).

Parameters
xInput value.
mrMemory resource.
Returns
Converted string value.

◆ convertContainedStringsToChars()

Value nk::builtin::convertContainedStringsToChars ( const Value & v,
std::pmr::memory_resource * mr = nullptr )

Recursively converts all contained strings in cells/structs to character vectors.

Parameters
vContainer value.
mrMemory resource.
Returns
Container with strings converted to char vectors.

◆ convertStringsToChars()

Value nk::builtin::convertStringsToChars ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Converts string arrays in input to character vectors (convertStringsToChars(x)).

Parameters
xInput value.
mrMemory resource.
Returns
Converted character array value.

◆ count()

Value nk::builtin::count ( const Value & str,
const Value & pat,
std::pmr::memory_resource * mr = nullptr )

Counts occurrences of pattern in string (count(str, pat)).

Parameters
strText to search.
patSubstring pattern.
mrMemory resource.
Returns
Count of occurrences.
See also
contains, strfind

◆ countFormatSpecs()

size_t nk::builtin::countFormatSpecs ( const std::string & fmt)

Counts number of conversion specifiers in format string.

Parameters
fmtFormat string.
Returns
Count of % conversion specifiers.

◆ deblank()

Value nk::builtin::deblank ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Removes trailing whitespace (deblank(s)).

Parameters
sInput text.
mrMemory resource.
Returns
Deblanked text.
See also
strtrim

◆ dec2base()

Value nk::builtin::dec2base ( const Value & d,
int base,
int minDigits = 0,
std::pmr::memory_resource * mr = nullptr )

Decimal to base-N string (dec2base(d, base, minDigits)).

Parameters
dNon-negative integer value(s).
baseRadix base (2 to 36).
minDigitsMinimum digits.
mrMemory resource.
Returns
Base-N character array.
See also
base2dec

◆ dec2bin()

Value nk::builtin::dec2bin ( const Value & d,
int minDigits = 0,
std::pmr::memory_resource * mr = nullptr )

Decimal to binary string (dec2bin(d, minDigits)).

Parameters
dNon-negative integer value(s).
minDigitsMinimum number of binary digits to output.
mrMemory resource.
Returns
Character array of binary representations.
See also
bin2dec, dec2hex

◆ dec2hex()

Value nk::builtin::dec2hex ( const Value & d,
int minDigits = 0,
std::pmr::memory_resource * mr = nullptr )

Decimal to hexadecimal string (dec2hex(d, minDigits)).

Parameters
dNon-negative integer value(s).
minDigitsMinimum number of hex digits to output.
mrMemory resource.
Returns
Character array of hex representations.
See also
hex2dec, dec2bin

◆ endsWith()

Value nk::builtin::endsWith ( const Value & str,
const Value & pat,
bool ignoreCase = false,
std::pmr::memory_resource * mr = nullptr )

Checks if string ends with pattern (endsWith(str, pat)).

Parameters
strText to search.
patSuffix pattern.
ignoreCaseCase-insensitive flag.
mrMemory resource.
Returns
Logical scalar or array.
See also
startsWith, contains

◆ erase()

Value nk::builtin::erase ( const Value & s,
const Value & pat,
std::pmr::memory_resource * mr = nullptr )

Erases occurrences of substring pattern from string (erase(s, pat)).

Parameters
sInput string.
patPattern to erase.
mrMemory resource.
Returns
String with pattern removed.

◆ eraseBetween()

Value nk::builtin::eraseBetween ( const Value & s,
const Value & start,
const Value & end,
std::pmr::memory_resource * mr = nullptr )

Erases text between specified boundaries (eraseBetween(s, start, end)).

Parameters
sOriginal string.
start1-based start position or pattern.
end1-based end position or pattern.
mrMemory resource.
Returns
Modified string.

◆ extract()

Value nk::builtin::extract ( const Value & s,
const Value & pat,
std::pmr::memory_resource * mr = nullptr )

Extracts substring matching pattern (extract(s, pat)).

Parameters
sInput string.
patPattern to extract.
mrMemory resource.
Returns
Extracted matching substring.

◆ extractAfter()

Value nk::builtin::extractAfter ( const Value & s,
const Value & p,
std::pmr::memory_resource * mr = nullptr )

Extracts substrings after specified pattern or position (extractAfter(s, p)).

Parameters
sInput string array.
pPosition index or pattern.
mrMemory resource.
Returns
Substring after boundary.

◆ extractBefore()

Value nk::builtin::extractBefore ( const Value & s,
const Value & p,
std::pmr::memory_resource * mr = nullptr )

Extracts substrings before specified pattern or position (extractBefore(s, p)).

Parameters
sInput string array.
pPosition index or pattern.
mrMemory resource.
Returns
Substring before boundary.

◆ extractBetween()

Value nk::builtin::extractBetween ( const Value & s,
const Value & start,
const Value & end,
std::pmr::memory_resource * mr = nullptr )

Extracts substrings between specified boundaries (extractBetween(s, start, end)).

Parameters
sInput string array.
start1-based start index or start pattern.
end1-based end index or end pattern.
mrMemory resource.
Returns
Extracted substring.

◆ formatCyclic()

std::string nk::builtin::formatCyclic ( const std::string & fmt,
Span< const Value > args,
size_t argStart = 0,
std::pmr::memory_resource * mr = nullptr )

Formats cyclic repetition of format specification across array elements.

Parameters
fmtFormat string.
argsSpan of arguments.
argStartStarting index in args.
mrMemory resource.
Returns
Formatted string.

◆ formatOnce()

std::string nk::builtin::formatOnce ( const std::string & fmt,
Span< const Value > args,
size_t argStart = 0,
bool literalWhenShort = false )

Formats single pass of format specification.

Parameters
fmtFormat string.
argsSpan of arguments.
argStartStarting index in args.
literalWhenShortFormat literal string flag when short.
Returns
Formatted string.

◆ hex2dec()

Value nk::builtin::hex2dec ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Hexadecimal string to decimal (hex2dec(s)).

Parameters
sHexadecimal text.
mrMemory resource.
Returns
Decimal value.
See also
dec2hex

◆ hex2num()

Value nk::builtin::hex2num ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Converts 16-character hexadecimal string to IEEE double-precision floating-point number (hex2num(s)).

Parameters
sHexadecimal character vector or string array.
mrMemory resource.
Returns
IEEE 754 double precision floating-point number.
See also
num2hex, hex2dec

◆ insertAfter()

Value nk::builtin::insertAfter ( const Value & s,
const Value & p,
const Value & newText,
std::pmr::memory_resource * mr = nullptr )

Inserts text after specified position or pattern (insertAfter(s, p, newText)).

Parameters
sOriginal string.
pPosition index or pattern.
newTextText to insert.
mrMemory resource.
Returns
Modified string.

◆ insertBefore()

Value nk::builtin::insertBefore ( const Value & s,
const Value & p,
const Value & newText,
std::pmr::memory_resource * mr = nullptr )

Inserts text before specified position or pattern (insertBefore(s, p, newText)).

Parameters
sOriginal string.
pPosition index or pattern.
newTextText to insert.
mrMemory resource.
Returns
Modified string.

◆ int2str()

Value nk::builtin::int2str ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Formats integer into character vector (int2str(x)).

Parameters
xInput integer or numeric value.
mrMemory resource.
Returns
Character vector representation.
See also
num2str, mat2str

◆ isletter()

Value nk::builtin::isletter ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Tests if characters are letters (isletter(s)).

Parameters
sInput text.
mrMemory resource.
Returns
Logical array matching shape of s.
See also
isspace, isstrprop

◆ isspace()

Value nk::builtin::isspace ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Tests if characters are whitespace (isspace(s)).

Parameters
sInput text.
mrMemory resource.
Returns
Logical array.
See also
isletter, isstrprop

◆ isspaceFn()

Value nk::builtin::isspaceFn ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Tests if characters are whitespace (internal helper returning Value).

Parameters
sInput text.
mrMemory resource.
Returns
Logical array.

◆ isstringscalar()

Value nk::builtin::isstringscalar ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Tests if input is a scalar string (isstringscalar(s)).

Parameters
sInput value.
mrMemory resource.
Returns
True if s is a 1x1 string array.

◆ isstrprop() [1/2]

Value nk::builtin::isstrprop ( const Value & s,
const std::string & category,
std::pmr::memory_resource * mr = nullptr )

Tests if characters have specified string property (isstrprop(s, category)).

Parameters
sInput text.
categoryProperty name (e.g. 'alpha', 'digit', 'alphanum', 'punct', 'upper', 'lower').
mrMemory resource.
Returns
Logical array.
See also
isletter, isspace

◆ isstrprop() [2/2]

Value nk::builtin::isstrprop ( const Value & s,
const Value & category,
std::pmr::memory_resource * mr = nullptr )

Tests if characters have specified string property via Value category (isstrprop(s, category)).

Parameters
sInput text.
categoryProperty name value.
mrMemory resource.
Returns
Logical array.

◆ join()

Value nk::builtin::join ( const Value & arr,
const Value & delim = Value::Empty,
std::pmr::memory_resource * mr = nullptr )

Combines elements of string array into single string (join(arr, delim)).

Parameters
arrInput string array.
delimDelimiter (default: empty).
mrMemory resource.
Returns
Joined string scalar.
See also
split, strjoin

◆ lower()

Value nk::builtin::lower ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Converts string to lowercase (lower(s)).

Parameters
sInput text.
mrMemory resource.
Returns
Lowercase text.
See also
upper

◆ mat2str() [1/2]

Value nk::builtin::mat2str ( const Value & x,
int precision,
std::pmr::memory_resource * mr = nullptr )

Formats matrix into MATLAB syntax string with precision (mat2str(x, precision)).

Parameters
xInput matrix.
precisionNumber of digits of precision.
mrMemory resource.
Returns
Formatted character vector.
See also
num2str

◆ mat2str() [2/2]

Value nk::builtin::mat2str ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Formats matrix into MATLAB syntax string (mat2str(x)).

Parameters
xInput matrix.
mrMemory resource.
Returns
Character vector formatted as MATLAB matrix literal [1, 2; 3, 4].
See also
num2str

◆ matches()

Value nk::builtin::matches ( const Value & str,
const Value & pat,
std::pmr::memory_resource * mr = nullptr )

Tests if strings match pattern (matches(str, pat)).

Parameters
strText array.
patPattern string.
mrMemory resource.
Returns
Logical array.
See also
contains, startsWith, endsWith

◆ newline()

Value nk::builtin::newline ( std::pmr::memory_resource * mr = nullptr)

Creates newline character string (newline).

Parameters
mrMemory resource.
Returns
1 x 1 string scalar containing "\n".

◆ newlineFn()

Value nk::builtin::newlineFn ( std::pmr::memory_resource * mr = nullptr)

Generates newline character as string Value.

Parameters
mrMemory resource.
Returns
Newline string value.

◆ num2hex()

Value nk::builtin::num2hex ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Converts double-precision floating-point number to 16-character hexadecimal string (num2hex(x)).

Parameters
xNumeric scalar or array.
mrMemory resource.
Returns
16-character hexadecimal string representation.
See also
hex2num, dec2hex

◆ num2str() [1/3]

Value nk::builtin::num2str ( const Value & x,
const std::string & fmt,
std::pmr::memory_resource * mr = nullptr )

Formats numeric array into character vector with format specification (num2str(x, fmt)).

Parameters
xInput numeric array or scalar.
fmtC-style printf format string (e.g. "%10.5f").
mrMemory resource.
Returns
Character vector representation.
See also
int2str, mat2str, str2num

◆ num2str() [2/3]

Value nk::builtin::num2str ( const Value & x,
int N,
std::pmr::memory_resource * mr = nullptr )

Formats numeric array into character vector with specified precision digits (num2str(x, N)).

Parameters
xInput numeric array or scalar.
NMaximum number of significant digits.
mrMemory resource.
Returns
Character vector representation.
See also
int2str, mat2str, str2num

◆ num2str() [3/3]

Value nk::builtin::num2str ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Formats numeric array into character vector (num2str(x)).

Parameters
xInput numeric array or scalar.
mrMemory resource for allocations (nullptr for default).
Returns
Character vector representation.
See also
int2str, mat2str, str2num

◆ pad()

Value nk::builtin::pad ( const Value & s,
size_t n,
const Value & side = Value(),
const Value & padChar = Value(),
std::pmr::memory_resource * mr = nullptr )

Pads string to fixed length (pad(s, n, side, padChar)).

Parameters
sInput string array.
nTarget minimum length.
sideDirection ("left", "right", or "both").
padCharCharacter used to pad (default space).
mrMemory resource.
Returns
Padded string array.

◆ rat()

Value nk::builtin::rat ( const Value & x,
double tol = 0.0,
std::pmr::memory_resource * mr = nullptr )

Rational approximation as fraction / continued fraction (rat(x, tol)).

Parameters
xInput floating-point value.
tolError tolerance (default: 0.0 for 1e-6 * norm(x,1)).
mrMemory resource.
Returns
Cell array {N, D} containing numerator and denominator.
See also
rats

◆ rats()

Value nk::builtin::rats ( const Value & x,
int len = 13,
std::pmr::memory_resource * mr = nullptr )

Formats numbers as rational string representations (rats(x, len)).

Parameters
xInput numeric array.
lenField length for each rational string (default: 13).
mrMemory resource.
Returns
Character array of formatted rational strings.
See also
rat

◆ regexp()

Value nk::builtin::regexp ( const Value & str,
const Value & pat,
std::pmr::memory_resource * mr = nullptr )

Regular expression matching (regexp(str, pat)).

Parameters
strText to search.
patRegular expression pattern.
mrMemory resource.
Returns
1-based match start indices or match tokens.
See also
regexpi, regexprep

◆ regexpFind()

Value nk::builtin::regexpFind ( const Value & s,
const Value & pat,
const std::string & option,
bool ignoreCase,
std::pmr::memory_resource * mr = nullptr )

Regular expression search helper.

Parameters
sInput text.
patRegular expression pattern.
optionMatch option string.
ignoreCaseCase-insensitive match flag.
mrMemory resource.
Returns
Match results Value.

◆ regexpFindOnce()

Value nk::builtin::regexpFindOnce ( const Value & s,
const Value & pat,
const std::string & option,
bool ignoreCase,
std::pmr::memory_resource * mr = nullptr )

Regular expression search once helper.

Parameters
sInput text.
patRegular expression pattern.
optionMatch option string.
ignoreCaseCase-insensitive match flag.
mrMemory resource.
Returns
First match result Value.

◆ regexpi()

Value nk::builtin::regexpi ( const Value & str,
const Value & pat,
std::pmr::memory_resource * mr = nullptr )

Case-insensitive regular expression matching (regexpi(str, pat)).

Parameters
strText to search.
patRegular expression pattern.
mrMemory resource.
Returns
Match start indices.
See also
regexp, regexprep

◆ regexprep()

Value nk::builtin::regexprep ( const Value & str,
const Value & pat,
const Value & rep,
bool ignoreCase = false,
bool once = false,
std::pmr::memory_resource * mr = nullptr )

Regular expression replacement (regexprep(str, pat, rep, ignoreCase, once)).

Parameters
strOriginal text.
patRegex pattern.
repReplacement string.
ignoreCaseCase-insensitive match flag.
onceReplace first match only flag.
mrMemory resource.
Returns
Text with matches replaced.
See also
regexp, strrep

◆ regexptranslate() [1/2]

Value nk::builtin::regexptranslate ( const std::string & type,
const std::string & str,
std::pmr::memory_resource * mr = nullptr )

Translates wildcard strings to regular expressions (regexptranslate(type, str)).

Parameters
typeTranslation type ("wildcard" or "escape").
strInput string.
mrMemory resource.
Returns
Regex pattern string.
See also
regexp

◆ regexptranslate() [2/2]

Value nk::builtin::regexptranslate ( const std::string & type,
const Value & str,
std::pmr::memory_resource * mr = nullptr )

Translates wildcard Value to regular expression (regexptranslate(type, str)).

Parameters
typeTranslation type ("wildcard" or "escape").
strInput string value.
mrMemory resource.
Returns
Regex pattern Value.

◆ replace()

Value nk::builtin::replace ( const Value & s,
const Value & oldPat,
const Value & newPat,
std::pmr::memory_resource * mr = nullptr )

Replaces substring pattern with new pattern in string array (replace(s, oldPat, newPat)).

Parameters
sInput string array.
oldPatPattern to replace.
newPatReplacement text.
mrMemory resource.
Returns
String array with replacements applied.

◆ replaceBetween()

Value nk::builtin::replaceBetween ( const Value & s,
const Value & start,
const Value & end,
const Value & newText,
std::pmr::memory_resource * mr = nullptr )

Replaces text between specified start and end boundaries (replaceBetween(s, start, end, newText)).

Parameters
sOriginal text.
start1-based start index or substring pattern.
end1-based end index or substring pattern.
newTextReplacement text.
mrMemory resource.
Returns
Text with range replaced.
See also
extractBetween, eraseBetween

◆ reverse()

Value nk::builtin::reverse ( const Value & str,
std::pmr::memory_resource * mr = nullptr )

Reverses characters in string (reverse(str)).

Parameters
strInput string.
mrMemory resource.
Returns
Reversed string.

◆ split()

Value nk::builtin::split ( const Value & s,
const Value & delim = Value::Empty,
std::pmr::memory_resource * mr = nullptr )

Splits string array elements by delimiter (split(s, delim)).

Parameters
sInput string array.
delimDelimiter pattern.
mrMemory resource.
Returns
Split string array or cell array.
See also
join, strsplit

◆ splitlines()

Value nk::builtin::splitlines ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Splits string into separate lines (splitlines(s)).

Parameters
sInput string.
mrMemory resource.
Returns
String array or cell array of individual lines.
See also
strsplit

◆ startsWith()

Value nk::builtin::startsWith ( const Value & str,
const Value & pat,
bool ignoreCase = false,
std::pmr::memory_resource * mr = nullptr )

Checks if string starts with pattern (startsWith(str, pat)).

Parameters
strText to search.
patPrefix pattern.
ignoreCaseCase-insensitive flag.
mrMemory resource.
Returns
Logical scalar or array.
See also
endsWith, contains

◆ str2double()

Value nk::builtin::str2double ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Converts text to double precision numeric values (str2double(s)).

Parameters
sText scalar or string array.
mrMemory resource.
Returns
Double-precision numeric values (NaN for non-convertible elements).
See also
str2num

◆ str2num()

Value nk::builtin::str2num ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Converts string representation to numeric matrix (str2num(s)).

Parameters
sCharacter vector or string.
mrMemory resource.
Returns
Parsed numeric matrix or empty array on parse failure.
See also
str2double, num2str

◆ strcat()

Value nk::builtin::strcat ( Span< const Value > args,
std::pmr::memory_resource * mr = nullptr )

Concatenates strings horizontally (strcat(s1, s2, ...)).

Parameters
argsSpan of string arguments.
mrMemory resource.
Returns
Concatenated string.
See also
strjoin

◆ strcmp()

Value nk::builtin::strcmp ( const Value & s1,
const Value & s2,
std::pmr::memory_resource * mr = nullptr )

Compares strings for exact equality (case-sensitive) (strcmp(s1, s2)).

Parameters
s1First string or cell/array.
s2Second string or cell/array.
mrMemory resource.
Returns
Logical array or boolean indicating exact elementwise equality.
See also
strcmpi, strncmp, strncmpi

◆ strcmpi()

Value nk::builtin::strcmpi ( const Value & s1,
const Value & s2,
std::pmr::memory_resource * mr = nullptr )

Compares strings for equality ignoring case (strcmpi(s1, s2)).

Parameters
s1First string.
s2Second string.
mrMemory resource.
Returns
Logical result.
See also
strcmp, strncmpi

◆ strfind()

Value nk::builtin::strfind ( const Value & text,
const Value & pattern,
std::pmr::memory_resource * mr = nullptr )

Finds occurrences of substring within string (strfind(text, pattern)).

Parameters
textInput text.
patternSubstring to find.
mrMemory resource.
Returns
1-based start indices of matches.
See also
strrep, contains

◆ string_array()

Value nk::builtin::string_array ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Converts input to string array (string(x)).

Parameters
xInput value.
mrMemory resource.
Returns
String array.
See also
char_array, toString

◆ stringsND()

Value nk::builtin::stringsND ( Span< const size_t > dims,
std::pmr::memory_resource * mr = nullptr )

Constructs an N-dimensional array of empty strings.

Parameters
dimsDimensions of the target string array.
mrMemory resource.
Returns
N-D string array initialized to empty strings.

◆ strip() [1/2]

Value nk::builtin::strip ( const Value & s,
const Value & side,
const Value & ch,
std::pmr::memory_resource * mr = nullptr )

Strips specified characters from side of string array (strip(s, side, ch)).

Parameters
sInput string array.
sideDirection ("left", "right", or "both").
chCharacters to strip.
mrMemory resource.
Returns
Stripped string array.

◆ strip() [2/2]

Value nk::builtin::strip ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Strips leading and trailing whitespace from string array (strip(s)).

Parameters
sInput string array.
mrMemory resource.
Returns
Stripped string array.
See also
strtrim

◆ strjoin() [1/2]

Value nk::builtin::strjoin ( const Value & arr,
const Value & delim,
std::pmr::memory_resource * mr = nullptr )

Joins string array with Value delimiter (strjoin(arr, delim)).

Parameters
arrString array or cell array.
delimDelimiter Value.
mrMemory resource.
Returns
Joined character vector.

◆ strjoin() [2/2]

Value nk::builtin::strjoin ( const Value & c,
const std::string & delim = " ",
std::pmr::memory_resource * mr = nullptr )

Joins string array or cell array of strings with delimiter (strjoin(c, delim)).

Parameters
cCell array or string array.
delimDelimiter string (default: " ").
mrMemory resource.
Returns
Joined character vector.
See also
strsplit, strcat

◆ strjust()

Value nk::builtin::strjust ( const Value & M,
const std::string & side = "left",
std::pmr::memory_resource * mr = nullptr )

Justifies character matrix (strjust(M, side)).

Parameters
MInput character matrix.
sideJustification side ("left", "right", "center").
mrMemory resource.
Returns
Justified character matrix.

◆ strlength()

Value nk::builtin::strlength ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Returns number of characters in each string element (strlength(s)).

Parameters
sInput string array.
mrMemory resource.
Returns
Array of element string lengths.

◆ strncmp()

Value nk::builtin::strncmp ( const Value & s1,
const Value & s2,
size_t n,
std::pmr::memory_resource * mr = nullptr )

Compares first n characters of strings (case-sensitive) (strncmp(s1, s2, n)).

Parameters
s1First string.
s2Second string.
nNumber of characters to compare.
mrMemory resource.
Returns
Logical result.
See also
strcmp, strncmpi

◆ strncmpi()

Value nk::builtin::strncmpi ( const Value & s1,
const Value & s2,
size_t n,
std::pmr::memory_resource * mr = nullptr )

Compares first n characters of strings ignoring case (strncmpi(s1, s2, n)).

Parameters
s1First string.
s2Second string.
nNumber of characters to compare.
mrMemory resource.
Returns
Logical result.
See also
strcmpi, strncmp

◆ strrep()

Value nk::builtin::strrep ( const Value & orig,
const Value & oldStr,
const Value & newStr,
std::pmr::memory_resource * mr = nullptr )

Replaces occurrences of substring within string (strrep(orig, old, new)).

Parameters
origOriginal string.
oldStrPattern to replace.
newStrReplacement string.
mrMemory resource.
Returns
Modified string.
See also
regexprep, strfind

◆ strsplit() [1/3]

Value nk::builtin::strsplit ( const Value & s,
const std::string & delim = " ",
std::pmr::memory_resource * mr = nullptr )

Splits string by delimiter string (strsplit(s, delim)).

Parameters
sInput string.
delimDelimiter string (default: " ").
mrMemory resource.
Returns
Cell array of split substrings.
See also
strjoin, splitlines, split

◆ strsplit() [2/3]

Value nk::builtin::strsplit ( const Value & s,
const Value & delim,
std::pmr::memory_resource * mr = nullptr )

Splits string by Value delimiter (strsplit(s, delim)).

Parameters
sInput string.
delimDelimiter value.
mrMemory resource.
Returns
Cell array of split substrings.

◆ strsplit() [3/3]

Value nk::builtin::strsplit ( const Value & s,
std::pmr::memory_resource * mr )

Splits string by whitespace (strsplit(s)).

Parameters
sInput string.
mrMemory resource.
Returns
Cell array of split substrings.

◆ strtok()

std::pair< Value, Value > nk::builtin::strtok ( const Value & str,
const std::string & delim = " \t\n\r",
std::pmr::memory_resource * mr = nullptr )

Extracts first token from character vector up to delimiter ([token, rem] = strtok(str, delim)).

Parameters
strInput string.
delimDelimiter characters (default: " \t\n\r").
mrMemory resource.
Returns
Pair of {token, remainder} character vectors.

◆ strtrim()

Value nk::builtin::strtrim ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Removes leading and trailing whitespace (strtrim(s)).

Parameters
sInput text.
mrMemory resource.
Returns
Trimmed text.
See also
deblank, strip

◆ toChar()

Value nk::builtin::toChar ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Alias for char_array conversion (char(x)).

Parameters
xInput value.
mrMemory resource.
Returns
Character array.
See also
char_array

◆ toString()

Value nk::builtin::toString ( const Value & x,
std::pmr::memory_resource * mr = nullptr )

Alias for string_array conversion (string(x)).

Parameters
xInput value.
mrMemory resource.
Returns
String array.
See also
string_array

◆ upper()

Value nk::builtin::upper ( const Value & s,
std::pmr::memory_resource * mr = nullptr )

Converts string to uppercase (upper(s)).

Parameters
sInput text.
mrMemory resource.
Returns
Uppercase text.
See also
lower

◆ validatestring()

Value nk::builtin::validatestring ( const Value & str,
const Value & validStrings,
std::pmr::memory_resource * mr = nullptr )

Validates text against list of valid strings (validatestring(str, validStrings)).

Parameters
strQuery string.
validStringsCell or array of valid candidate strings.
mrMemory resource.
Returns
Unambiguous matched string from validStrings.