Substring - StringUtil: Difference between revisions
Jump to navigation
Jump to search
imported>JohnB m (→See Also) |
m (Convert source tags to syntaxhighlight) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 7: | Line 7: | ||
== Syntax == | == Syntax == | ||
< | <syntaxhighlight lang="papyrus"> | ||
string Function Substring(string | string Function Substring(string s, int startIndex, int len = 0) global native | ||
</ | </syntaxhighlight> | ||
== Parameters == | == Parameters == | ||
* | *s: The string from which to retrieve the substring. | ||
*startIndex: Starting character position of a substring. | *startIndex: Starting character position of a substring. | ||
*len: An optional length of the substring. Default of 0 means for the entire string. | *len: An optional length of the substring. Default of 0 means for the entire string. | ||
| Line 22: | Line 22: | ||
== Examples == | == Examples == | ||
< | <syntaxhighlight lang="papyrus"> | ||
Import StringUtil | Import StringUtil | ||
| Line 34: | Line 34: | ||
string s4 = Substring(ss, 0, -1) | string s4 = Substring(ss, 0, -1) | ||
;"sample string" | ;"sample string" | ||
</ | </syntaxhighlight> | ||
== Notes == | == Notes == | ||
Latest revision as of 20:23, 5 September 2026
SKSE Member of: StringUtil Script
Returns a portion of the string starting at given index, optionally with specified amount of characters. (This function requires SKSE)
Syntax[edit | edit source]
string Function Substring(string s, int startIndex, int len = 0) global nativeParameters[edit | edit source]
- s: The string from which to retrieve the substring.
- startIndex: Starting character position of a substring.
- len: An optional length of the substring. Default of 0 means for the entire string.
- Default: 0
Return Value[edit | edit source]
Portion from the given string. Returns none if the given startIndex was invalid.
Examples[edit | edit source]
Import StringUtil
string ss = "Sample string"
string s1 = Substring(ss, 5)
;"e string"
string s2 = Substring(ss, 2, 4)
;"mple"
string s3 = Substring(ss, 20)
;none
string s4 = Substring(ss, 0, -1)
;"sample string"Notes[edit | edit source]
Invalid len value will work as if 0 was given.
This function is case-insensitive (like all SKSE string functions right now).