Skip to content

k.utils.string ​

String and HTML text processing (KText)

Execution ContextPrerequisitesTypical Use
KScript API, Page / View server scriptsNoneStripping rich-text HTML tags, generating summaries, and case-insensitive edits

The script path is k.utils.string (KText type), providing HTML stripping, substring extraction, and case-insensitive replacement or removal.

Quick Start ​

js
k.api.get("cleanText", () => {
  const plain = k.utils.string.removeHtml("<p>Hello <b>Kooboo</b> World</p>")
  const summary = k.utils.string.sementicSubString(plain, 0, 14)
  return { plain, summary }
})

Quick Reference ​

Method / PropertyDescriptionReturns
removeHtml(input)Remove HTML tags from a stringstring
subString(input, start, count)Extract a substring (throws if start + count exceeds length)string
sementicSubString(input, start, count)Extract a substring along word or semantic boundaries (returns null if start is past the end or only whitespace remains)string | null
replace(input, oldValue, newValue)Perform case-insensitive substring replacementstring
remove(input, valueToRemove)Remove matching substrings case-insensitivelystring

Methods ​

All five k.utils.string methods take a source string and return the transformed result (sementicSubString() may return null).

MethodDescription
removeHtml(input)Remove HTML tags
subString(input, start, count)Extract substring (throws if start + count exceeds string length)
sementicSubString(input, start, count)Extract substring along word/semantic boundaries (returns null if start is past the end or remaining characters are whitespace)
replace(input, oldValue, newValue)Case-insensitive replace
remove(input, valueToRemove)Case-insensitive substring removal
ParameterTypeRequiredDescription
inputstringYesSource string
startnumberYesStart index; values below 0 are treated as 0
countnumberYesLength to take
oldValuestringYesOld value to replace, case-insensitive
newValuestringYesNew value
valueToRemovestringYesValue to remove, case-insensitive

Returns: string; sementicSubString() returns string | null (null when start is beyond the string length—including empty strings—or when the remaining slice is all whitespace).

js
const plain = k.utils.string.removeHtml("<p>Hi</p>")
const part = k.utils.string.subString("hello world", 0, 5)
const semantic = k.utils.string.sementicSubString("Kooboo builds websites", 0, 12)
const normalized = k.utils.string.replace("Hello KOOboo", "kooboo", "Kooboo")
const removed = k.utils.string.remove("SKU-001-draft", "-draft")

TypeScript Definitions ​

ts
interface KText {
  removeHtml(input: string): string;
  sementicSubString(input: string, start: number, count: number): string | null;
  subString(input: string, start: number, count: number): string;
  replace(input: string, oldValue: string, newValue: string): string;
  remove(input: string, ValueToRemove: string): string;
}