Nasal library/string: Difference between revisions

Jump to navigation Jump to search
m
sort alphabetic
m (One character vs. String distinction)
m (sort alphabetic)
Line 71: Line 71:


== String Functions ==
== String Functions ==
=== string.trim(str,lr[,func]) ===
Trim spaces at the left (lr < 0), at the right (lr > 0), or both (lr = 0) is default.
An optional function argument defines which characters should be trimmed:
<syntaxhighlight lang="nasal">
string.trim(a);                                    # trim spaces           
string.trim(a, 1, string.isdigit);                # trim digits at the right
string.trim(a, 0, func(c) c == `\\` or c == `/`);  # trim slashes/backslashes
</syntaxhighlight>
=== string.lc() ===
Return string converted to lower case letters.
<syntaxhighlight lang="nasal">
string.lc();
</syntaxhighlight>
=== string.uc() ===
Return string converted to upper case letters.
<syntaxhighlight lang="nasal">
string.uc();
</syntaxhighlight>
=== string.icmp() ===
=== string.icmp() ===
Case insensitive string compare function.
Case insensitive string compare function.
Line 98: Line 80:
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
string.imatch();
string.imatch();
</syntaxhighlight>
=== string.join(sep,list) ===
Join all elements of a list inserting a separator between every two of them.
<syntaxhighlight lang="nasal">
string.join(sep,list);
</syntaxhighlight>
=== string.lc() ===
Return string converted to lower case letters.
<syntaxhighlight lang="nasal">
string.lc();
</syntaxhighlight>
</syntaxhighlight>
=== string.match(str, patt) ===
=== string.match(str, patt) ===
Line 134: Line 126:
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
string.normpath();
string.normpath();
</syntaxhighlight>
=== string.join(sep,list) ===
Join all elements of a list inserting a separator between every two of them.
<syntaxhighlight lang="nasal">
string.join(sep,list);
</syntaxhighlight>
</syntaxhighlight>
=== string.replace(str,old,new) ===
=== string.replace(str,old,new) ===
Line 159: Line 146:
</syntaxhighlight>
</syntaxhighlight>
The result vector will be set to [3, 123.456].
The result vector will be set to [3, 123.456].
=== string.trim(str,lr[,func]) ===
Trim spaces at the left (lr < 0), at the right (lr > 0), or both (lr = 0) is default.
An optional function argument defines which characters should be trimmed:
<syntaxhighlight lang="nasal">
string.trim(a);                                    # trim spaces           
string.trim(a, 1, string.isdigit);                # trim digits at the right
string.trim(a, 0, func(c) c == `\\` or c == `/`);  # trim slashes/backslashes
</syntaxhighlight>
=== string.uc() ===
Return string converted to upper case letters.
<syntaxhighlight lang="nasal">
string.uc();
</syntaxhighlight>


=== string.compileTemplate(template,type=nil) ===
=== string.compileTemplate(template,type=nil) ===
546

edits

Navigation menu