MutableString

MutableString

A class representing a mutable string, allowing character modifications, insertions, deletions, replacements, appending, and removing from both the start and end.

Constructor

new MutableString(initialString)

Description:
  • Initializes a new instance of the MutableString class.
Source:
Parameters:
Name Type Description
initialString string The initial string to use as the basis for the mutable string.

Methods

append(str)

Description:
  • Appends a string to the end of the mutable string.
Source:
Parameters:
Name Type Description
str string The string to append to the mutable string.

charAt(index) → {string}

Description:
  • Gets the character at a specified index.
Source:
Parameters:
Name Type Description
index number The position of the character to retrieve.
Returns:
- The character at the specified index.
Type
string

clear()

Description:
  • Clears all characters from the mutable string by truncating the array.
Source:

delete(index)

Description:
  • Deletes a character at a specified index.
Source:
Parameters:
Name Type Description
index number The position of the character to delete.

insert(index, str)

Description:
  • Inserts a character or string at a specified index.
Source:
Parameters:
Name Type Description
index number The position to insert the character or string.
str string The string to insert at the given index.

length() → {number}

Description:
  • Returns the current length of the mutable string.
Source:
Returns:
- The length of the mutable string.
Type
number

prepend(str)

Description:
  • Prepends a string to the beginning of the mutable string.
Source:
Parameters:
Name Type Description
str string The string to prepend to the mutable string.

removeFromEnd(n) → {string}

Description:
  • Removes the last n characters from the mutable string.
Source:
Parameters:
Name Type Description
n number The number of characters to remove from the end.
Returns:
- The characters that were removed.
Type
string

removeFromStart(n) → {string}

Description:
  • Removes the first n characters from the mutable string.
Source:
Parameters:
Name Type Description
n number The number of characters to remove from the beginning.
Returns:
- The characters that were removed.
Type
string

replace(target, replacement)

Description:
  • Replaces all occurrences of a substring with a new string.
Source:
Parameters:
Name Type Description
target string The substring to replace.
replacement string The string to replace the target substring with.

setCharAt(index, char)

Description:
  • Sets a character at a specific index.
Source:
Parameters:
Name Type Description
index number The position to set the character.
char string The character to set. Only the first character is used if a string is passed.

toString() → {string}

Description:
  • Converts the mutable string back to a regular string.
Source:
Returns:
- The current string value.
Type
string