String Library - Person8880/Shine GitHub Wiki

Overview

The string library included with Shine extends the string table with extra useful functions.

string.Explode

string.Explode( String, string Separator )

Separates the given string, using the given separator. For example:

local Words = string.Explode( "This is a sentence.", " " )

PrintTable( Words )

--[[
Output:
> 1 = This
> 2 = is
> 3 = a
> 4 = sentence.
]]

string.IsValidUTF8

string.IsValidUTF8( Character )

Returns true if the given character is a valid UTF-8 encoded character. Some inputs passed through the "OnPlayerType" event are not valid UTF-8.

string.TimeToString

string.TimeToString( number Time )

Returns a nicely formatted string of the given time. For example:

Print( string.TimeToString( 130 ) )

--[[
Output:
> 2 minutes and 10 seconds
]]

string.DigitalTime

string.DigitalTime( number Time )

Returns a digital clock style representation of the time in the form "Minutes:Seconds".

Print( string.DigitalTime( 130 ) )

--[[
Output:
> 02:10
]]

string.UTF8Char

string.UTF8Char( Number )

Returns a string containing the UTF-8 character represented by the given numerical value. Values less than 0 or greater than 0x10FFFF will result in an error as they are outside UTF-8's character range.

string.UTF8Encode

string.UTF8Encode( String )

Returns a table containing all UTF-8 characters contained in the given string. Any byte-sequences that violate UTF-8 encoding rules are replaced with U+FFFD.

string.UTF8Length

string.UTF8Length( String )

Returns the number of UTF-8 characters in the string. This is useful to get the real number of characters in a string, as the string.len function and the # operator return the number of bytes, not the number of characters.

string.UTF8Lower

string.UTF8Lower( String )

Lowercases the string including many UTF-8 characters that the standard string.lower would miss.

string.UTF8Reverse

string.UTF8Reverse( String )

Returns the string reversed including UTF-8 characters, which would not be output correctly with the standard string.reverse.

string.UTF8Sub

string.UTF8Sub( String, LowerBound[, UpperBound ])

Behaves the same as string.sub, but taking one UTF-8 character as one unit instead of one byte.

string.UTF8Upper

string.UTF8Upper( String )

Uppercases the string including many UTF-8 characters that the standard string.upper would miss.