StringUtil
Utility library of useful string functions.
Types
StrokeData
interface
StrokeData {
Joins:
(
"miter"
|
"round"
|
"bevel"
)
?
|
Enum.LineJoinMode?
--
The type of joins the stroke has.
Thickness:
number?
--
The thickness
Transparency:
number?
--
The transparency of the stroke.
}
Functions
color
StringUtil.
color
(
text:
string
,
--
The text to apply the color to.
) →
string
--
The new string with the color applied.
Returns a string with the given color applied to it.
stroke
StringUtil.
stroke
(
text:
string
,
--
The text to apply the stroke to.
) →
string
--
The new string with the stroke applied.
Returns a string with the given stroke applied to it.
rich
StringUtil.
rich
(
text:
string
,
--
The text to apply the options to.
options:
{
Bold:
boolean?
,
Italic:
boolean?
,
Underline:
boolean?
,
}
--
The options to apply to the text.
) →
string
--
The new string with the options applied.
Returns a string with the given options applied to it.
formatAssetId
StringUtil.
formatAssetId
(
id:
string
|
number
--
The asset id to format.
) →
string
--
The formatted asset id.
Ensures a given number or string is formatted as an asset id.
StringUtil.formatAssetId(123456) -- "rbxassetid://123456"
StringUtil.formatAssetId("123456") -- "rbxassetid://123456"
StringUtil.formatAssetId("rbxassetid://123456") -- "rbxassetid://123456"
formatNumberWithCommas
StringUtil.
formatNumberWithCommas
(
num:
number
|
string
) →
string
Formats a number with commas.
StringUtil.formatNumberWithCommas("12") -- "12"
StringUtil.formatNumberWithCommas(1234) -- "1,234"
StringUtil.formatNumberWithCommas(123456) -- "123,456"
StringUtil.formatNumberWithCommas("1234567") -- "1,234,567"
StringUtil.formatNumberWithCommas(12345.6789) -- "12,345.6789"
truncateNumberWithSuffix
StringUtil.
truncateNumberWithSuffix
(
num:
number
|
string
,
config:
{
MaxDecimals:
number?
,
ShowZeroes:
boolean?
,
AddSpace:
boolean?
,
}
?
) →
string
Truncates a number to its nearest factor of 1000 and replaces the chopped off numbers with an appropriate suffix to enable easier reading.
- MaxDecimals: The maximum number of decimals to show. [Default: 1]
- ShowZeroes: Whether to always show zeroes after the decimal point.
- AddSpace: Whether to add a space between the number and the suffix
StringUtil.truncateNumberWithSuffix(1.234) -- 1.2
StringUtil.truncateNumberWithSuffix(123) -- 123
StringUtil.truncateNumberWithSuffix(123, {MaxDecimals = 2, ShowZeroes = true}) -- 123.00
StringUtil.truncateNumberWithSuffix(1234) -- 1.2K
StringUtil.truncateNumberWithSuffix(123456) -- 123.5K
StringUtil.truncateNumberWithSuffix(123456, {MaxDecimals = 1}) -- 123.4K
StringUtil.truncateNumberWithSuffix("123456", {MaxDecimals = 2}) -- 123.45K
StringUtil.truncateNumberWithSuffix(123456, {MaxDecimals = 3}) -- 123.456K
StringUtil.truncateNumberWithSuffix(123456789) -- 123.4M
StringUtil.truncateNumberWithSuffix(1234567890) -- 1.2B
formatTime
StringUtil.
formatTime
(
inputTime:
number
,
--
The time to format.
inputTimeType:
string?
,
--
The type of time that is being given to format. (d, h, m, s, ds, cs, ms)
outputStringFormat:
string?
,
--
The format of the output string. Must separated by colons, if you put a number before the timetype it will make sure the number has atleast that length, adding zeroes before it as needed. By default it will be (2h:2m:2s)
config:
{
HideParentZeroValues:
boolean?
,
Delimeter:
string?
,
}
?
) →
string
--
The formatted time string.
Takes a number, a string defining the type of time given, and an output format and formats it to a pleasing structure ideal for displaying time.
Examples:
StringUtil.formatTime(3600, "s", "2h:2m:2s") -- "01:00:00"
StringUtil.formatTime(125, "s", "2h:2m:2s") -- "00:02:05"
StringUtil.formatTime(125, "s", "1h:1m:1s") -- "0:2:5"
StringUtil.formatTime(125, "s", "h:m:s") -- "0:2:5"
StringUtil.formatTime(125, "s", "2h:2m:2s", {HideParentZeroValues = true}) -- "02:05"
StringUtil.formatTime(125, "s", "h:m:s:ds") -- "0:2:5:0"
StringUtil.formatTime(125, "s", "h:m:s:ds", {HideParentZeroValues = true}) -- "2:5:0"
StringUtil.formatTime(3725, "s", "h:s") -- "1:125"
StringUtil.formatTime(1000, "ms", "s") -- "1"