stripBom method

  1. @useResult
String stripBom()

Removes the UTF-8 BOM (U+FEFF) from the start of this string if present.

Returns this string without a leading BOM, or unchanged if none.

Example:

'\uFEFFhello'.stripBom(); // 'hello'
'hello'.stripBom();       // 'hello'

Implementation

@useResult
String stripBom() {
  if (isEmpty) return this;
  if (startsWith('\uFEFF')) return replaceRange(0, 1, '');
  return this;
}