Back to Intellij Community

ReplaceWithStringBuilderAppendRange

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/ReplaceWithStringBuilderAppendRange.html

2025.3-rc-2690 B
Original Source

Reports a StringBuilder.append(CharArray, offset, len) function call on the JVM platform that should be replaced with a StringBuilder.appendRange(CharArray, startIndex, endIndex) function call.

The append function behaves differently on the JVM, JS and Native platforms, so using the appendRange function is recommended.

Example:

fun f(charArray: CharArray, offset: Int, len: Int): String {
      return buildString {
          append(charArray, offset, len)
      }
  }

After the quick-fix is applied:

fun f(charArray: CharArray, offset: Int, len: Int): String {
      return buildString {
          appendRange(charArray, offset, offset + len)
      }
  }