StringUtil Script: Difference between revisions

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Kahmul
(uppercase -> lowercase)
m (Convert source tags to syntaxhighlight)
 
(8 intermediate revisions by 5 users not shown)
Line 6: Line 6:


Collection of generic string utility global functions. (These global functions require SKSE)
Collection of generic string utility global functions. (These global functions require SKSE)
A comment found at the top of this script, still present as of SKSE64 version 2.2.6, reads:
<blockquote>
Note about the internal Skyrim implementation of the string classes used for scripting:
The strings are case-insensitive. Each BSFixedString is managed in a cache and reused everywhere it is needed.  This means that strings like "O" and "o" are technically equivalent. Which string is used depends greatly on which version is found first. We are investigating how to manage this, but for the time being be aware that the distinction between uppercase and lowercase may not exist. It also means that functions below returning an integer for the character may not correspond exactly. Also GetNthChar("Hello Skyrim!", 4) will return a string with either "O" or "o" depending on which might be registered first. All my tests so far have it return the uppercase, even though in the string it is lowercase. We may solve this problem by switching back to returning an integer rather than a string for GetNthChar, but this will still have problems.
</blockquote>


== Definition ==
== Definition ==
<source lang="papyrus">
<syntaxhighlight lang="papyrus">
ScriptName StringUtil
ScriptName StringUtil
</source>
</syntaxhighlight>


== Properties ==
== Properties ==
Line 16: Line 23:


== SKSE Global Functions ==
== SKSE Global Functions ==
'''int Function [[GetLength - StringUtil|GetLength]](string str)'''
*Returns the length of the string.
'''string Function [[GetNthChar - StringUtil|GetNthChar]](string str, int n)'''
*Returns the character at n in str as a string.


'''bool Function [[IsUppercase - StringUtil|IsUppercase]](string c)'''
:'''Int [[GetLength - StringUtil|GetLength]](String ''str'')'''
*Returns whether the character is uppercase or not.
:*Returns the length of the string.


'''bool Function [[IsLowercase - StringUtil|IsLowercase]](string c)'''
:'''String [[GetNthChar - StringUtil|GetNthChar]](String ''str'', Int ''n'')'''
*Returns whether the character is lowercase or not.
:*Returns the character at n in str as a string.


'''bool Function [[IsLetter - StringUtil|IsLetter]](string c)'''
:'''Bool [[IsLetter - StringUtil|IsLetter]](String ''c'')'''
*Returns whether the character is a letter or not.
:*Returns whether the character is a letter or not.


'''bool Function [[IsDigit - StringUtil|IsDigit]](string c)'''
:'''Bool [[IsDigit - StringUtil|IsDigit]](String ''c'')'''
*Returns whether the character is a digit or not.
:*Returns whether the character is a digit or not.


'''bool Function [[IsPunctuation - StringUtil|IsPunctuation]](string c)'''
:'''Bool [[IsPunctuation - StringUtil|IsPunctuation]](String ''c'')'''
*Returns whether the character is punctuation or not.
:*Returns whether the character is punctuation or not.


'''string Function [[ToUpper - StringUtil|ToUpper]](string str)'''
:'''Bool [[IsPrintable - StringUtil|IsPrintable]](String ''c'')'''
*Returns the string as uppercase.
:*Returns whether the character is printable or not.


'''string Function [[ToLower - StringUtil|ToLower]](string str)'''
:'''Int [[Find - StringUtil|Find]](String ''str'', String ''toFind'', Int ''startIndex'')'''
*Returns the string as lowercase.
:*Returns the index of the first occurence of specified phrase inside the string, starting at given position.


'''int Function [[Find - StringUtil|Find]](string str, string input, int start)'''
:'''String [[Substring - StringUtil|Substring]](String ''str'', Int ''startIndex'', Int ''len'')'''
*Returns the index of the input found in the string starting at start.
:*Returns a portion of the string starting at given index with specified amount of characters.


'''int Function [[Substring - StringUtil|Substring]](string str, int start, int len)'''
:'''Int [[AsOrd - StringUtil|AsOrd]](String ''c'')'''
*Returns a portion of the string starting at start until len amount of characters.
:*Returns the decimal value of a character.


'''int Function [[AsOrd - StringUtil|AsOrd]](string c)'''
:'''String [[AsChar - StringUtil|AsChar]](Int ''c'')'''
*Returns the character as a number.
:*Returns the decimal as a string character.


'''string Function [[AsChar - StringUtil|AsChar]](int c)'''
:'''String[] [[Split - StringUtil|Split]](String ''s'', String ''delim'')'''
*Returns the number as a string character.
:*Returns array of strings separated by the specified delimiter.


== Member Functions ==
== Member Functions ==

Latest revision as of 20:23, 5 September 2026


Collection of generic string utility global functions. (These global functions require SKSE)

A comment found at the top of this script, still present as of SKSE64 version 2.2.6, reads:

Note about the internal Skyrim implementation of the string classes used for scripting:

The strings are case-insensitive. Each BSFixedString is managed in a cache and reused everywhere it is needed.  This means that strings like "O" and "o" are technically equivalent. Which string is used depends greatly on which version is found first. We are investigating how to manage this, but for the time being be aware that the distinction between uppercase and lowercase may not exist. It also means that functions below returning an integer for the character may not correspond exactly. Also GetNthChar("Hello Skyrim!", 4) will return a string with either "O" or "o" depending on which might be registered first. All my tests so far have it return the uppercase, even though in the string it is lowercase. We may solve this problem by switching back to returning an integer rather than a string for GetNthChar, but this will still have problems.

Definition[edit | edit source]

ScriptName StringUtil

Properties[edit | edit source]

None

SKSE Global Functions[edit | edit source]

Int GetLength(String str)
  • Returns the length of the string.
String GetNthChar(String str, Int n)
  • Returns the character at n in str as a string.
Bool IsLetter(String c)
  • Returns whether the character is a letter or not.
Bool IsDigit(String c)
  • Returns whether the character is a digit or not.
Bool IsPunctuation(String c)
  • Returns whether the character is punctuation or not.
Bool IsPrintable(String c)
  • Returns whether the character is printable or not.
Int Find(String str, String toFind, Int startIndex)
  • Returns the index of the first occurence of specified phrase inside the string, starting at given position.
String Substring(String str, Int startIndex, Int len)
  • Returns a portion of the string starting at given index with specified amount of characters.
Int AsOrd(String c)
  • Returns the decimal value of a character.
String AsChar(Int c)
  • Returns the decimal as a string character.
String[] Split(String s, String delim)
  • Returns array of strings separated by the specified delimiter.

Member Functions[edit | edit source]

None

Events[edit | edit source]

None