Skip to main content
Module

x/tstl/benchmark/internal/StringUtil.ts>StringUtil

TypeScript-STL (Standard Template Library, migrated from C++)
Go to Latest
class StringUtil
import { StringUtil } from "https://deno.land/x/tstl@v2.4.11/benchmark/internal/StringUtil.ts";

Static Properties

private
SPACE_ARRAY: Array<string>

An array containing whitespaces.

Static Methods

private
_Fetch_substitute_index(format: string): number
private
_Similar(
first: string,
second: string,
percent?: number,
)
private
_Substitute_sql_string(str: string): string
between(
str: string,
start?: string,
end?: string,
): string

Generate a substring.

Extracts a substring consisting of the characters from specified start to end. It's same with str.substring( ? = (str.find(start) + start.size()), str.find(end, ?) )

let str: string = StringUtil.between("ABCD(EFGH)IJK", "(", ")");
console.log(str); // PRINTS "EFGH"
  • If start is not specified, extracts from begin of the string to end.
  • If end is not specified, extracts from start to end of the string.
  • If start and end are all omitted, returns str, itself.
betweens(
str: string,
start?: string,
end?: string,
): Array<string>

Fetch substrings.

Splits a string into an array of substrings dividing by specified delimeters of start and end. It's the array of substrings adjusted the between.

ltrim(str: string, ...args: string[]): string

Remove all designated characters from the beginning of the specified string.

numberFormat(val: number, precision?: number): string

Number to formatted string with "," sign.

Returns a string converted from the number rounded off from specified precision with "," symbols.

removeHTMLSpaces(str: string): string

Replace all HTML spaces to a literal space.

repeat(str: string, n: number): string

Repeat a string.

Returns a string consisting of a specified string concatenated with itself a specified number of times.

replaceAll(
str: string,
before: string,
after: string,
): string

Returns a string specified word is replaced.

replaceAll(str: string, ...pairs: [string, string][]): string

Returns a string specified words are replaced.

rtrim(str: string, ...args: string[]): string

Remove all designated characters from the end of the specified string.

similarity(x: string, y: string): number
substitute(format: string, ...args: any[]): string

Substitute {n} tokens within the specified string.

substituteSQL(format: string, ...args: any[]): string

Substitute {n} tokens within the specified SQL-string.

trim(str: string, ...args: string[]): string

Remove all designated characters from the beginning and end of the specified string.