RAS standard library
Strings
These are string extension methods (ras_text of the RAS standard library). You can call them from any module without importing anything, as in s.width(). Only the methods you use are emitted into the VBA module RAS_Text.
export function fixedWidth(name: string, price: int): string {
// count half-width as 1 and full-width as 2, cut to 20 columns and pad the right with spaces
const head = name.leftWidth(20);
return head + " ".repeat(20 - head.width()) + `${price}`;
}
export function similar(a: string, b: string): boolean {
return a.countMatchChars(b) * 2 >= a.length;
}
For the built-in string methods (split, trim, includes, replace, etc.), see the cheat sheet and §15.4.1 of the specification. split can also split on a regular expression (s.split(/\s*,\s*/)), and trim accepts the characters to remove (" x ".trim(" ")).
Reference
Extension method (string) string.width
function width(this: string): int
Width of the string counting half-width characters as 1 and full-width characters as 2 (same as the Shift_JIS byte count; used for column widths of fixed-length text).
Half-width characters are ASCII characters and half-width katakana (ア, ゙, 。 and so on).
Example: "カナ漢字abc".width() → 9
Extension method (string) string.leftWidth
function leftWidth(this: string, n: int): string
The leading part that fits in width n (half-width 1, full-width 2). A full-width character of which only half would fit is not included.
Example: "漢字abc".leftWidth(3) → "漢", "abc".leftWidth(5) → "abc"
Extension method (string) string.rightWidth
function rightWidth(this: string, n: int): string
The trailing part that fits in width n (half-width 1, full-width 2). A full-width character of which only half would fit is not included.
Example: "abc漢字".rightWidth(5) → "c漢字"
Extension method (string) string.midWidth
function midWidth(this: string, start: int, n: int = -1): string
The part that fits in width n starting at width position start (from 0; half-width 1, full-width 2), to the end when n is omitted.
A full-width character whose second half lies at start is not included.
Example: "12漢字34".midWidth(2, 4) → "漢字", "12漢字34".midWidth(3) → "字34"
Extension method (string) string.toValue
function toValue(this: string): any
Converts the string to a value of the type that fits its content (for values read from CSV or text files and so on).
"TRUE" / "FALSE" (any case) become booleans, anything readable as a number (including full-width digits and digit grouping) becomes a double,
anything readable as a date ("2026/4/1") becomes a date, and anything else stays the same string.
Example: "1,200".toValue() → 1200, "2026/4/1".toValue() → a date, "abc".toValue() → "abc"
Extension method (string) string.countMatchChars
function countMatchChars(this: string, other: string): int
Number of characters the two strings have in common (in any order; a character is counted as many times as it appears in both). Used to measure how close two inconsistently written names are.
Example: "Main Street".countMatchChars("Street Main") → 11
Extension method (string) string.longestCommonSubsequence
function longestCommonSubsequence(this: string, other: string): string
The longest common subsequence of the two strings (the longest sequence of characters that appears in both in the same order, possibly with other characters in between).
Example: "ABCBDAB".longestCommonSubsequence("BDCABA") → "BDAB"