dart_common_utilities icon indicating copy to clipboard operation
dart_common_utilities copied to clipboard

removeAt only removes first match

Open DTayloe opened this issue 1 year ago • 0 comments

You can see in the source code that removeAt(int index) only removes the first match:

  /// remove the character in [index] of the given string.
  String removeAt(int index) {
    var selectStr = _mainStr[index];
    return _mainStr.replaceFirst('$selectStr', '');
  }

This implementation is wrong. The following code shows how this can appear:

//          01234567
var str1 = "12.34.56";
print(str1.stringUtils().removeAt(5));

The element at position 5 was not removed, instead the element at position 2 was.

DTayloe avatar Jun 09 '24 17:06 DTayloe