removeSuffixIgnoreCase static method

String removeSuffixIgnoreCase(
  1. String? str,
  2. String suffix
)

忽略大小写去掉指定后缀

@param str 字符串 @param suffix 后缀 @return 切掉后的字符串,若后缀不是 suffix, 返回原字符串

Implementation

static String removeSuffixIgnoreCase(String? str, String suffix) {
  if (isEmpty(str) || isEmpty(suffix)) {
    return str ?? '';
  }

  final strLower = str!.toLowerCase();
  final suffixLower = suffix.toLowerCase();
  if (strLower.endsWith(suffixLower)) {
    return str.substring(0, str.length - suffix.length);
  }
  return str;
}