insert method

  1. @useResult
String insert(
  1. String newChar,
  2. int position
)

Returns a new string with newChar inserted at the specified position.

Returns the original string if position is out of bounds.

Implementation

@useResult
String insert(String newChar, int position) {
  if (position < 0 || position > length) {
    return this;
  }

  return substringSafe(0, position) + newChar + substringSafe(position);
}