Difference between revisions of "String"
Jump to navigation
Jump to search
(Mention immutabiltiy) |
(Added some methods) |
||
| Line 1: | Line 1: | ||
<c>string</c> is one of the core [[:Category:Data Types|data types]] in MiniScript. | <c>string</c> is one of the core [[:Category:Data Types|data types]] in MiniScript. | ||
| − | Strings in MiniScript are immutable. | + | Strings in MiniScript are immutable. Because of this operations which would modify the string return a new one instead. |
| + | |||
| + | == Methods == | ||
| + | |||
| + | {| class="wikitable" | ||
| + | |- | ||
| + | ! Method !! Description | ||
| + | |- | ||
| + | | len || Returns the length of the string | ||
| + | |- | ||
| + | | indexOf(''substring'') || Returns the index of the first occurrence of ''substring'' in the string, or <c>null</c> if not found | ||
| + | |- | ||
| + | | remove(''substring'') || Returns a new string with the first occurrence of ''substring'' removed | ||
| + | |- | ||
| + | | insert(''index'', ''otherString'') || Returns a new string with ''otherString'' inserted at ''index'' | ||
| + | |- | ||
| + | | replace(''substring'', ''otherString'', ''maxCount'') || Returns a new list replacing occurrences of ''substring'' with ''otherString'' at most ''maxCount'', if specified. If ''maxCount'' is omitted it replaces '''all''' occurrences. | ||
| + | |- | ||
| + | | indexes || Returns a list with the indexes of the characters of the string | ||
| + | |- | ||
| + | | values || Returns a list of each character that make up the string | ||
| + | |} | ||
== See also == | == See also == | ||
Revision as of 12:01, 6 December 2021
string is one of the core data types in MiniScript.
Strings in MiniScript are immutable. Because of this operations which would modify the string return a new one instead.
Methods
| Method | Description |
|---|---|
| len | Returns the length of the string |
| indexOf(substring) | Returns the index of the first occurrence of substring in the string, or null if not found
|
| remove(substring) | Returns a new string with the first occurrence of substring removed |
| insert(index, otherString) | Returns a new string with otherString inserted at index |
| replace(substring, otherString, maxCount) | Returns a new list replacing occurrences of substring with otherString at most maxCount, if specified. If maxCount is omitted it replaces all occurrences. |
| indexes | Returns a list with the indexes of the characters of the string |
| values | Returns a list of each character that make up the string |
See also
- stringUtil - for additional operations on strings
This article is a stub. You can help the MiniScript Wiki by expanding it.