getFirstDiffChar method

  1. @useResult
String getFirstDiffChar(
  1. String other
)

Returns the first character where this string and other differ, or an empty string if they are identical.

Implementation

@useResult
String getFirstDiffChar(String other) {
  final int minLength = length < other.length ? length : other.length;

  for (int i = 0; i < minLength; i++) {
    if (this[i] != other[i]) {
      return other[i];
    }
  }

  if (length > other.length) {
    return this[minLength];
  }

  if (other.length > length) {
    return other[minLength];
  }

  return '';
}