Awkl
Loading...
Searching...
No Matches
str Namespace Reference

Functions

auto idx (string s, number i) -> string|number
 Index a string as if first character has index 1.
 
auto idx0 (string s, number i) -> string|number
 Index a string as if first character has index 0, with negative indexing.
 
string slice (string s, number a, number b)
 Slice a string as if first character has index 1.
 
string slice0 (string s, number a, number b)
 Slice a string as if first character has index 0.
 
auto find (string s1, string s2, number a, number b) -> string|number
 Lowest index starting from 1 where a substring is found in a string or its slice starting from 1.
 
auto find0 (string s1, string s2, number a, number b) -> string|number
 Lowest index starting from 0 where a substring is found in a string or its slice starting from 0.
 
auto indices (array R, string s1, string s2)
 Get indices, starting from 1, where a substring is found in a string, non-overlapping.
 
auto rfind (string s1, string s2, number a, number b) -> string|number
 Highest index starting from 1 where a substring is found in a string or its slice starting from 1.
 
auto rfind0 (string s1, string s2, number a, number b) -> string|number
 Highest index starting from 0 where a substring is found in a string or its slice starting from 0.
 
unassigned partition (array A, string s, string sep)
 Split the string at the first occurrence of a separator.
 
unassigned rpartition (array A, string s, string sep)
 Split the string at the last occurrence of a separator.
 
number splitLines (string s, array A)
 Split lines in a string at line boundaries.
 
string join (array A, string s=" ")
 Join array elements with separator.
 
number startsWith (string s1, string s2)
 Check if string starts with specific prefix.
 
number endsWith (string s1, string s2)
 Check if string ends with specific suffix.
 
string rep (string s, number n)
 Repeat string n number of times.
 
string escapeRe (string s)
 Escape regex special characters.
 
string replaceIdx (string s, string rep, number idx)
 Replace a character in a specific index with a string.
 
string replaceRange (string s, string rep, number i, number n)
 Replace a string in a specific index range with a string. Similar to substr()
 
string rmPrefix (string s, string pre)
 Remove matching prefix.
 
string rmSuffix (string s, string suf)
 Remove matching suffix.
 
string lstrip (string s, string chars)
 Remove leading characters.
 
string rstrip (string s, string chars)
 Remove trailing characters.
 
string strip (string s, string chars)
 Remove leading and trailing characters.
 
unassigned chars (array A, string s, number i0=1)
 Fill indexed array with characters in a string.
 
unassigned fields (array A)
 Fill indexed array with awk fields.
 
string lc (string s)
 Lower case.
 
string uc (string s)
 Upper case.
 
auto ucfirst (s)
 Upper case first character.
 
auto lcfirst (s)
 Lower case first character.
 
string tc (string s)
 Title case a string.
 
string tclc (string s)
 Title case a string and rest lower case.
 
string ltrim (string s)
 Remove leading blanks.
 
string rtrim (string s)
 Remove trailing blanks.
 
string trim (string s)
 Remove leading and trailing blanks.
 
string chop (string s, number n=1)
 Remove last characters.
 
string chomp (string s)
 Remove last character if it is linebreak \n
 
string rev (string s)
 Revert string.
 
string chr (number n)
 Chr function.
 
auto _ord_init (number l=0, number h=1114111)
 Fill the ord table.
 
number ord (string s)
 Ord function.
 
string indent (string s, string|number i)
 Indent.
 
string ljust (string s, number w, string c=" ", number l)
 Left justify.
 
string rjust (string s, number w, string c=" ", number l)
 Right justify.
 
auto serialize (x)
 Serialized representation of a string.
 
string repr (any x)
 String representation of a variable.
 
string csvQuote (string s)
 CSV-quote a string.
 
auto comb ()
 

Variables

string lower = "abcdefghijklmnopqrstuvwxyz"
 Lower-case letters in ASCII. Like POSIX [:lower:]
 
string upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 Upper-case letters in ASCII. Like POSIX [:upper:]
 
string digit = "0123456789"
 Digits in ASCII. Like POSIX [:digit:]
 
string alpha = lower upper
 Alphabetic characters in ASCII. Like POSIX [:alpha:]
 
string alnum = alpha digit
 Alphanumeric characters in ASCII. Like POSIX [:alnum:]
 
string word = alnum "_"
 Alphanumeric characters and _
 
string xdigit = "abcdefABCDEF" digit
 Hexadecimal digits in ASCII. Like POSIX [:xdigit:]
 
string blank = " \t"
 Blank characters in ASCII: space and tab. Like POSIX [:blank:]
 
string space = " \t\r\n\v\f"
 Space characters in ASCII: space, tab, carriage return, linebreak, vertical tab and form feed. Like POSIX [:space:]
 
string ascii
 ASCII characters.
 
string cntrl
 Control characters in ASCII. Unicode C0 control code. Like POSIX [:cntrl:]
 
string graph
 Graphical characters: Alphanumeric characters and punctuations. Like POSIX [:graph:]
 
string print_ = " " graph
 Printable characters: Space and graphical characters. Like POSIX [:print:]
 
string punct = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
 Punctuation characters in ASCII. Like POSIX [:punct:]
 
string ascii_letters = alpha
 
string ascii_lowercase = lower
 
string ascii_uppercase = upper
 
string digits = digit
 
string hexdigits = xdigit
 
string octdigits = "01234567"
 Octal digits in ASCII.
 
string punctuation = punct
 
string whitespace = space
 
string printable = digit alpha punct space
 
string linebounds = "\n\r\v\f\034\035\205\342\200\250\342\200\251"
 Single character line boundaries.
 
number _ordtab_init = 0
 
array ORDTAB [1]
 

Function Documentation

◆ _ord_init()

auto str::_ord_init ( number l = 0,
number h = 1114111 )

Fill the ord table.

Parameters
lLower bound
hUpper bound
Note
By default fills with the whole Unicode set (0x110000 or 1'114'112 elements) except the characters that aren't encodable with UTF-8

◆ chars()

unassigned str::chars ( array A,
string s,
number i0 = 1 )

Fill indexed array with characters in a string.

Parameters
[out]AIndexed array to fill with characters
sString from which to extract characters
i0Starting index of the indexed array
Returns

◆ chomp()

string str::chomp ( string s)

Remove last character if it is linebreak \n

Parameters
sOriginal string
Returns
String with last character removed if it is linebreak \n

◆ chop()

string str::chop ( string s,
number n = 1 )

Remove last characters.

Parameters
sOriginal string
nNumber of characters to remove. Optional
Returns
String with n last characters removed

◆ chr()

string str::chr ( number n)

Chr function.

Parameters
nDecimal integer representation of a character in the system's character set
Returns
Character
Note
On systems that use the Unicode character set, the parameter is the Unicode codepoint in decimal

◆ comb()

auto str::comb ( )

◆ csvQuote()

string str::csvQuote ( string s)

CSV-quote a string.

Parameters
sOriginal string
Returns
Quoted version of the string usable as a CSV field

◆ endsWith()

number str::endsWith ( string s1,
string s2 )

Check if string ends with specific suffix.

Parameters
s1String to match for suffix
s2Suffix to match
Returns
1 if successful, 0 if not

◆ escapeRe()

string str::escapeRe ( string s)

Escape regex special characters.

Parameters
sString to escape
Returns
String with characters \+*?[^]$(){}=!<>|:- escaped

◆ fields()

unassigned str::fields ( array A)

Fill indexed array with awk fields.

Parameters
[out]AIndexed array to fill with current awk fields ($1, $2, etc.)
Returns

◆ find()

auto str::find ( string s1,
string s2,
number a,
number b ) -> string | number

Lowest index starting from 1 where a substring is found in a string or its slice starting from 1.

Parameters
s1Containing string
s2Substring to find in containing string
aStart slice index of containing string starting from 1. Optional
bEnd slice index inclusive of containing string starting from 1. Optional
Returns
Lowest index found, starting from 1. 0 if substring was not found

◆ find0()

auto str::find0 ( string s1,
string s2,
number a,
number b ) -> string | number

Lowest index starting from 0 where a substring is found in a string or its slice starting from 0.

Parameters
s1Containing string
s2Substring to find in containing string
aStart slice index of containing string starting from 0. Optional
bEnd slice index exclusive of containing string starting from 0. Optional
Returns
Lowest index found, starting from 0. -1 if substring was not found

◆ idx()

auto str::idx ( string s,
number i ) -> string | number

Index a string as if first character has index 1.

Parameters
sString to be indexed
iIndex integer. From 1 to the length of the string
Returns
Character indexed from the string. 0 if out of bounds

◆ idx0()

auto str::idx0 ( string s,
number i ) -> string | number

Index a string as if first character has index 0, with negative indexing.

Parameters
sString to be indexed
iIndex integer. From minus the length of the string to the length of the string minus 1
Returns
Character indexed from the string. 0 if out of bounds

◆ indent()

string str::indent ( string s,
string|number i )

Indent.

Parameters
sOriginal string
iIndentation string or number of spaces to indent
Returns
String with each line indented with another string or a number of spaces
Todo
negative parameter for unindenting

◆ indices()

auto str::indices ( array R,
string s1,
string s2 )

Get indices, starting from 1, where a substring is found in a string, non-overlapping.

Parameters
RArray to be filled with indices starting from 1. If not found, the array is just deleted
s1Containing string
s2Substring to find in containing string
Todo
overlapping version

◆ join()

string str::join ( array A,
string s = " " )

Join array elements with separator.

Parameters
AArray to get elements from
sSeparator
Returns
Joined result

◆ lc()

string str::lc ( string s)

Lower case.

Parameters
sOriginal string
Returns
String to lower case

◆ lcfirst()

auto str::lcfirst ( s )

Lower case first character.

◆ ljust()

string str::ljust ( string s,
number w,
string c = " ",
number l )

Left justify.

Parameters
sOriginal string
wWidth
cCharacter to pad with
lAlternative string length. Default: length of s
Returns
Left jutified string: with w width filled with c characters to its right

◆ lstrip()

string str::lstrip ( string s,
string chars )

Remove leading characters.

Parameters
sOriginal string
charsCharacters to remove
Returns
String with characters from the beginning removed

◆ ltrim()

string str::ltrim ( string s)

Remove leading blanks.

Parameters
sOriginal string
Returns
String with blank characters from the beginning removed

◆ ord()

number str::ord ( string s)

Ord function.

Parameters
sCharacter. If a string is passed, it only uses its first character
Returns
Integer representation of a character in the system's character set
Note
On systems that use the Unicode character set, the result is the Unicode codepoint in decimal

◆ partition()

unassigned str::partition ( array A,
string s,
string sep )

Split the string at the first occurrence of a separator.

Parameters
[out]A

Array to be filled with 3 string elements:

  1. Before the first occurrence of the separator
  2. The separator itself
  3. After the separator

If the separator is not found, the 1° element is the whole string, and the rest are empty strings

sString
sepSeparator
Returns

◆ rep()

string str::rep ( string s,
number n )

Repeat string n number of times.

Parameters
sString to repeat
nNumber of times to repeat
Returns
Repeated string result

◆ replaceIdx()

string str::replaceIdx ( string s,
string rep,
number idx )

Replace a character in a specific index with a string.

Parameters
sOriginal string
repReplacement string
idxIndex in which to insert the replacement
Returns
String with a character at an index replaced with another string

◆ replaceRange()

string str::replaceRange ( string s,
string rep,
number i,
number n )

Replace a string in a specific index range with a string. Similar to substr()

Parameters
sOriginal string
repReplacement string
iStart index of substring to replace
nNumber of characters to replace
Returns
String with a substring range replaced with another string

◆ repr()

string str::repr ( any x)

String representation of a variable.

Parameters
xVariable
Returns
String representing a variable, depending on its type

◆ rev()

string str::rev ( string s)

Revert string.

Parameters
sOriginal string
Returns
String reversed character by character

◆ rfind()

auto str::rfind ( string s1,
string s2,
number a,
number b ) -> string | number

Highest index starting from 1 where a substring is found in a string or its slice starting from 1.

Parameters
s1Containing string
s2Substring to find in containing string
aStart slice index of containing string starting from 0. Optional
bEnd slice index inclusive of containing string starting from 0. Optional
Returns
Highest index found, starting from 1. 0 if substring was not found

◆ rfind0()

auto str::rfind0 ( string s1,
string s2,
number a,
number b ) -> string | number

Highest index starting from 0 where a substring is found in a string or its slice starting from 0.

Parameters
s1Containing string
s2Substring to find in containing string
aStart slice index of containing string starting from 0. Optional
bEnd slice index exclusive of containing string starting from 0. Optional
Returns
Highest index found, starting from 0. -1 if substring was not found

◆ rjust()

string str::rjust ( string s,
number w,
string c = " ",
number l )

Right justify.

Parameters
sOriginal string
wWidth
cCharacter to pad with
lAlternative string length. Default: length of s
Returns
Right jutified string: with w width filled with c characters to its left

◆ rmPrefix()

string str::rmPrefix ( string s,
string pre )

Remove matching prefix.

Parameters
sString from which to remove a prefix
prePrefix to remove
Returns
String without the prefix

◆ rmSuffix()

string str::rmSuffix ( string s,
string suf )

Remove matching suffix.

Parameters
sString from which to remove a suffix
sufSuffix to remove
Returns
String without the suffix

◆ rpartition()

unassigned str::rpartition ( array A,
string s,
string sep )

Split the string at the last occurrence of a separator.

Parameters
[out]A

Array to be filled with 3 string elements

  1. Before the last occurrence of the separator
  2. The separator itself
  3. After the separator

If the separator is not found, the 1° element is the whole string, and the rest are empty strings

sString
sepSeparator
Returns

◆ rstrip()

string str::rstrip ( string s,
string chars )

Remove trailing characters.

Parameters
sOriginal string
charsCharacters to remove
Returns
String with characters from the end removed

◆ rtrim()

string str::rtrim ( string s)

Remove trailing blanks.

Parameters
sOriginal string
Returns
String with blank characters from the end removed

◆ serialize()

auto str::serialize ( x )

Serialized representation of a string.

◆ slice()

string str::slice ( string s,
number a,
number b )

Slice a string as if first character has index 1.

Parameters
sString to be sliced
aStart index starting from 1
bEnd index inclusive starting from 1. Optional
Returns
Substring sliced from the string

◆ slice0()

string str::slice0 ( string s,
number a,
number b )

Slice a string as if first character has index 0.

Parameters
sString to be sliced
aStart index starting from 0
bEnd index exclusive starting from 0. Optional
Returns
Substring sliced from the string

◆ splitLines()

number str::splitLines ( string s,
array A )

Split lines in a string at line boundaries.

Parameters
sOriginal string
AArray to be filled with line contents
Returns
Number of lines found
Todo
Keep boundaries boolean parameter

◆ startsWith()

number str::startsWith ( string s1,
string s2 )

Check if string starts with specific prefix.

Parameters
s1String to match for prefix
s2Prefix to match
Returns
1 if successful, 0 if not

◆ strip()

string str::strip ( string s,
string chars )

Remove leading and trailing characters.

Parameters
sOriginal string
charsCharacters to remove
Returns
String with characters characters from the beginning and end removed

◆ tc()

string str::tc ( string s)

Title case a string.

Parameters
sOriginal string
Returns
String with its first character in upper case
Todo
Handle correctly Unicode characters that have title case mappings

◆ tclc()

string str::tclc ( string s)

Title case a string and rest lower case.

Parameters
sOriginal string
Returns
String with its first character in upper case and the rest lower case
Todo
Handle Unicode characters that have title case mappings

◆ trim()

string str::trim ( string s)

Remove leading and trailing blanks.

Parameters
sOriginal string
Returns
String with blank characters from the beginning and end removed

◆ uc()

string str::uc ( string s)

Upper case.

Parameters
sOriginal string
Returns
String to upper case

◆ ucfirst()

auto str::ucfirst ( s )

Upper case first character.

Variable Documentation

◆ _ordtab_init

number str::_ordtab_init = 0

◆ alnum

string str::alnum = alpha digit

Alphanumeric characters in ASCII. Like POSIX [:alnum:]

◆ alpha

string str::alpha = lower upper

Alphabetic characters in ASCII. Like POSIX [:alpha:]

◆ ascii

string str::ascii
Initial value:
= "\
\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\
\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\
\040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\
\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\
\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\
\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\
\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\
\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177"

ASCII characters.

◆ ascii_letters

string str::ascii_letters = alpha

◆ ascii_lowercase

string str::ascii_lowercase = lower

◆ ascii_uppercase

string str::ascii_uppercase = upper

◆ blank

string str::blank = " \t"

Blank characters in ASCII: space and tab. Like POSIX [:blank:]

◆ cntrl

string str::cntrl
Initial value:
= "\
\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\
\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\
\177"

Control characters in ASCII. Unicode C0 control code. Like POSIX [:cntrl:]

◆ digit

string str::digit = "0123456789"

Digits in ASCII. Like POSIX [:digit:]

◆ digits

string str::digits = digit

◆ graph

string str::graph
Initial value:
= "\
\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\
\060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\
\100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\
\120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\
\140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\
\160\161\162\163\164\165\166\167\170\171\172\173\174\175\176"

Graphical characters: Alphanumeric characters and punctuations. Like POSIX [:graph:]

◆ hexdigits

string str::hexdigits = xdigit

◆ linebounds

string str::linebounds = "\n\r\v\f\034\035\205\342\200\250\342\200\251"

Single character line boundaries.

◆ lower

string str::lower = "abcdefghijklmnopqrstuvwxyz"

Lower-case letters in ASCII. Like POSIX [:lower:]

◆ octdigits

string str::octdigits = "01234567"

Octal digits in ASCII.

◆ ORDTAB

array str::ORDTAB[1]

◆ print_

string str::print_ = " " graph

Printable characters: Space and graphical characters. Like POSIX [:print:]

◆ printable

string str::printable = digit alpha punct space

◆ punct

string str::punct = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"

Punctuation characters in ASCII. Like POSIX [:punct:]

◆ punctuation

string str::punctuation = punct

◆ space

string str::space = " \t\r\n\v\f"

Space characters in ASCII: space, tab, carriage return, linebreak, vertical tab and form feed. Like POSIX [:space:]

◆ upper

string str::upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Upper-case letters in ASCII. Like POSIX [:upper:]

◆ whitespace

string str::whitespace = space

◆ word

string str::word = alnum "_"

Alphanumeric characters and _

◆ xdigit

string str::xdigit = "abcdefABCDEF" digit

Hexadecimal digits in ASCII. Like POSIX [:xdigit:]