functions Static Methods 96

Angles (self)
Angles
Returns the angles of a uniformly random rotation.
AsInt (value)
int
Base64Decode (base64EncodedData)
string
Convert from a base64 encoded string
Base64Encode (plainText)
string
Convert to a base64 encoded string
BitsSet (i)
int
Returns the number of bits set in an integer. This us usually used for flags to count the amount of flags set.
CatmullRomSpline (points, interpolation)
IEnumerable`1
CheckValidationAttributes (prop, obj, errors, name)
bool
Check all System.ComponentModel.DataAnnotations.ValidationAttributes on this property, and get the error messages if there are any.
Clamp (input, min, max)
T
Clamp a number between two values.
Clone (dict)
Dictionary`2
CollapseSpacesAndPreserveLines (str)
string
Collapse sequences of spaces and tabs into a single space, preserving newlines
CollapseWhiteSpace (str)
string
Collapse sequences of whitespace into a single whitespace
Color (self)
Color
Returns a random Color
Columnize (str, maxLength, right)
string
convert "string" into "string " or " string"
Contains (value, flag)
bool
Distance (source, target)
int
Return the distance between two strings. Useful for ordering strings by similarity
Double (self, min, max)
Double
Returns a double between min and max
FastHash (str)
int
Generate a 32-bit truncated xxhash3 hash from given string.
FastHash64 (str)
UInt64
Generate a 64-bit xxhash3 hash from given string.
Float (self)
float
Returns a random float between 0 and 1
FloatDeterministic (self, i)
float
Get a random float (0-1) from a pre-calculated list. This is faster, and if you put the same seed in, it will always return the same number. The downside is that it only has 8192 variations of floats, but that seem like enough for most things.
ForEachTaskAsync (source, body, maxRunning, token)
Task
FormatBytes (input, shortFormat)
string
Given a number, will format as a memory value, ie 10gb, 4mb
FormatNumberShort (num)
string
"1500" becomes "1,500", "15 000" becomes "15K", "15 000 000" becomes "15KK", etc.
FormatSeconds (secs)
string
Formats the given value in format "1w2d3h4m5s". Will not display 0 values.
FormatSecondsLong (secs)
string
Formats the given value in format "4 weeks, 3 days, 2 hours and 1 minutes". Will not display 0 values. Will not display seconds if value is more than 1 hour.
FormatWithSuffix (num)
string
Change 1 to 1st, 2 to 2nd etc
FromArray (self, array, defVal)
T
Returns a random value in an array
FromBase36 (input)
long
Decode the Base36 Encoded string into a number
FromList (self, array, defVal)
T
Gaussian (self, mean, stdDev)
float
Sample from a Gaussian distribution with a given mean and standard deviation.
Gaussian2D (self, mean, stdDev)
Vector2
Gaussian3D (self, mean, stdDev)
Vector3
Gaussian4D (self, mean, stdDev)
Vector4
GetAttributeOfType (enumVal)
T
Gets an attribute on an enum field value
GetCommonBaseType (types)
Type
GetEpoch (d)
int
Returns the UNIX time stamp - number of seconds since 1st of January, 1970.
GetFilenameSafe (input)
string
Make the passed in string filename safe. This replaces any invalid characters with "_".
GetManagedSize (t)
int
Get the managed size of a given type. This matches an IL-level sizeof(t), even if it cannot be determined normally in C#. Note that sizeof(t) != Marshal.SizeOf(t) when t is char or bool.
GetOrCreate (dict, key)
TValue
GetPropertyValue (jso, membername, defaultvalue)
T
Get a property value by name, from a JsonObject. Return defaultValue if it's not found.
HtmlEncode (str)
string
Humanize (dateTime)
string
Convert date into a human readable relative time string.
Int (self, min, max)
int
Returns a random int between min and max (inclusive)
InvokeWithWarning (action)
Call an action, swallow any exceptions with a warning
IsBasedOnGenericType (src, test)
bool
Returns if this type is based on a given generic type.
IsInitOnly (property)
bool
Determine if this property is init-only.
IsPowerOfTwo (x)
bool
Return true if the number is a power of two (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, etc)
IsValid (obj)
bool
Returns false if Sandbox.IValid object is null or if Sandbox.IValid.IsValid returns false.
IsValidTag (source)
bool
Is this string a valid Tag. This is a way to check if a string is a valid tag, project wide. So our logic is always the same. - not null - between 1 and 32 chars - a-z
KiloFormat (num)
string
Format a large number into "1045M", "56K"
Md5 (input)
string
Get the md5 hash of a string.
NormalizeFilename (str, enforceInitialSlash)
string
Puts a filename into the format /path/filename.ext (from path\FileName.EXT)
Plural (a, single, plural)
string
Return single if 1 else plural
QuoteSafe (str, optional)
string
Puts quote marks around a string. Internal quotes are backslashed.
ReadNullTerminatedString (stream, offset)
string
Read a null terminated string from the stream, at given offset.
RemoveBadCharacters (str)
string
Removes bad, invisible characters that are commonly used to exploit. https://en.wikipedia.org/wiki/Zero-width_non-joiner
Rotation (self)
Rotation
Returns a uniformly random rotation.
SimplifyPath (str)
string
Gets rid of ../'s (from /path/folder/../file.txt to /path/file.txt)
SizeFormat (bytes)
string
Snippet (source, find, padding)
string
Given a large string, find all occurrences of a substring and return them with padding. This is useful in situations where you're searching for a word in a hug body of text, and want to show how it's used without displaying the whole text.
SplitQuotesStrings (input)
String[]
in : I am "splitting a" string "because it's fun " out : ["I", "am", "splitting a", "string", "because it's fun"]
TcbSpline (points, interpolation, tension, continuity, bias)
IEnumerable`1
ToBase36 (i)
string
Encode the given number into a Base36 string
ToBool (str)
bool
Try to convert to bool. Inputs can be true, false, yes, no, 0, 1, null (caps insensitive)
ToDateTime (seconds)
DateTime
Converts UNIX time stamp to a DateTime object.
ToDecimal (str, Default)
Decimal
128-bit data type that returns sane results for almost any input. All other numeric types can cast from this.
ToDouble (str, Default)
float
Convert to System.Double, if not then return .
ToDoubleEval (expression, Default)
Double
Convert to System.Double. Might be a string formula. This is always going to be slower than a call to Sandbox.SandboxSystemExtensions.ToDouble(System.String,System.Single).
ToFloat (str, Default)
float
Convert to System.Single, if not then return .
ToFloatEval (expression, Default)
float
Convert to System.Single. Might be a string formula. This is always going to be slower than a call to Sandbox.SandboxSystemExtensions.ToFloat(System.String,System.Single).
ToGuid (input)
Guid
Take a string and create a deterministic guid.
ToInt (str, Default)
int
Convert to System.Int32, if not then return .
ToIntEval (expression, Default)
int
Convert to System.Int32. Might be a string formula. This is always going to be slower than a call to Sandbox.SandboxSystemExtensions.ToInt(System.String,System.Int32).
ToLong (str, Default)
long
Convert to System.Int64, if not then return .
ToLongEval (expression, Default)
long
Convert to System.Int64. Might be a string formula. This is always going to be slower than a call to Sandbox.SandboxSystemExtensions.ToLong(System.String,System.Int64).
ToMetric (input, decimals)
string
Convert 1100 to 1.1k
ToRelativeTimeString (dateTime)
string
ToRemainingTimeString (span)
string
ToSimpleString (type, includeNamespace)
string
Returns this type's name, with nicer formatting for generic types.
ToTitleCase (source)
string
Convert a variable name to something more user friendly.
ToType (str, t)
object
Try to politely convert from a string to another type
ToUInt (str, Default)
UInt32
Convert to System.UInt32, if not then return .
ToULong (str, Default)
UInt64
Convert to System.UInt64, if not then return .
TrimQuoted (str, ignoreSurroundingSpaces)
string
The string might start and end in quotes ( ", ' ), remove those if that is the case.
Truncate (str, maxLength, appendage)
string
If the string is longer than this amount of characters then truncate it If appendage is defined, it will be appended to the end of truncated strings (ie, "..")
TruncateFilename (str, maxLength, appendage)
string
If the string is longer than this amount of characters then truncate it If appendage is defined, it will be appended to the end of truncated strings (ie, "..")
TryToType (str, t, Value)
bool
Try to politely convert from a string to another type
UnsignedMod (a, b)
int
Does what you expected to happen when you did "a % b", that is, handles negative values by returning a positive number from the end.
UrlEncode (str)
string
VectorInCircle (self, radius)
Vector2
Uniformly samples a 2D position from all points with distance at most from the origin.
VectorInCube (self, extents)
Vector3
Uniformly samples a 3D position from a cube with coordinates in the range - to +.
VectorInSphere (self, radius)
Vector3
Uniformly samples a 3D position from all points with distance at most from the origin.
VectorInSquare (self, extents)
Vector2
Uniformly samples a 2D position from a square with coordinates in the range - to +.
WildcardMatch (str, wildcard)
bool
Returns true if this string matches a wildcard match. Check is case insensitive. Supports '*' (zero or more chars) and '?' (exactly one char) wildcards. The backslash character '\' escapes '*' to match it literally.
WithExtension (path, ext)
string
Adds or replaces the extension of to .
WithFlag (value, flag, set)
T
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.