StringExt extension

  • @Author: chuxiong
  • @Created at: 2023/3/2 4:03 下午
  • @Email:
  • @Company: 嘉联支付
  • description String扩展:覆盖空值判定、数值解析、金额/千分位/手机号脱敏、URL 处理、全半角等。 依赖:decimal(纯 Dart,金额 / 千分位格式化用)。
on

Properties

defaultMoneyStr → String

Available on String?, provided by the StringExt extension

空值处理:null / 空串返回 "0.00"(金额占位)。
no setter
defaultString → String

Available on String?, provided by the StringExt extension

空值处理:null / 空串返回 "--"。
no setter
formatMoney → String

Available on String?, provided by the StringExt extension

金额格式化。
no setter
fullToHalf → String

Available on String?, provided by the StringExt extension

字符串全角转半角
no setter
isNullOrEmpty → bool

Available on String?, provided by the StringExt extension

是否为 null 或空字符串。
no setter
isUrl → bool

Available on String?, provided by the StringExt extension

是否为合法 URL(粗匹配)。
no setter
isValidChineseMobile → bool

Available on String?, provided by the StringExt extension

是否为中国大陆手机号(正则 ^1[3-9]\d{9}$)。
no setter
maskMobile → String

Available on String?, provided by the StringExt extension

分级星号脱敏手机号(原地升级:不再限定 11 位原样返回)。
no setter
notNullStr → String

Available on String?, provided by the StringExt extension

返回非空字符串:null / 空串转换为 ""。
no setter
parseIntWithDefault → int

Available on String?, provided by the StringExt extension

解析为 int,失败或 null 返回 0。
no setter
thousandSeparated → String

Available on String?, provided by the StringExt extension

千分位数字字符串(仅接受 ^\d+(\.\d+)?$,否则原样返回)。
no setter

Methods

abbreviate(int maxWidth, {int offset = 0}) → String?

Available on String?, provided by the StringExt extension

使用点缩写字符串。
compare(String? other) → int

Available on String?, provided by the StringExt extension

比较两个字符串是否相同,返回 -1/0/1。
containsAny(List<Pattern> searchPatterns, [int startIndex = 0]) → bool

Available on String?, provided by the StringExt extension

判断一个字符串是否包含任何给定的搜索模式。
containsIgnoreCase(String other) → bool

Available on String?, provided by the StringExt extension

字符串匹配/搜索,忽略大小写
defaultStrWithEmpty({String? emptyStr}) → String

Available on String?, provided by the StringExt extension

空值处理:null / 空串返回 emptyStr(默认 "--")。
formatDigitPattern({int digit = 4, String pattern = ' '}) → String

Available on String?, provided by the StringExt extension

每隔 x 位加 pattern。比如用来格式化银行卡。
formatDigitPatternEnd({int digit = 4, String pattern = ' '}) → String

Available on String?, provided by the StringExt extension

每隔 x 位加 pattern,从末尾开始。
formatSpace4() → String

Available on String?, provided by the StringExt extension

每隔 4 位加空格。
hammingDistance(String other) → int

Available on String?, provided by the StringExt extension

比较两个长度一样的字符串有几个字符不同。
hideNumber({int start = 3, int end = 7, String replacement = '****'}) → String

Available on String?, provided by the StringExt extension

隐藏手机号中间 n 位。
maskMiddle({int head = 0, int tail = 0, String placeholder = '****'}) → String

Available on String?, provided by the StringExt extension

保留头尾、掩码中间的通用脱敏。
maskMiddleOr({String fallback = '', int head = 0, int tail = 0, String placeholder = '****'}) → String

Available on String?, provided by the StringExt extension

maskMiddle 的空值安全版:null / 空串返回 fallback(默认 '')。
maskMobileOr({String fallback = ''}) → String

Available on String?, provided by the StringExt extension

maskMobile 的空值安全版:null / 空串返回 fallback。
moneyFormatWithUnit(bool autoMoneyUnit) → String

Available on String?, provided by the StringExt extension

金额格式化(带单位)。
removeUrlProtocol() → String

Available on String?, provided by the StringExt extension

移除 URL 协议(http:// / https://)。null / 空串返回 ''。
reverse() → String

Available on String?, provided by the StringExt extension

反转字符串。
startsWithAny(List<Pattern> prefixes, [int index = 0]) → bool

Available on String?, provided by the StringExt extension

判断一个字符串以任何给定的前缀开始。
substringSafe(int start, [int? end]) → String

Available on String?, provided by the StringExt extension

越界安全的 substring:start/end 自动夹到 [0, length]; null / 空串返回 ''。
toDouble() → double?

Available on String?, provided by the StringExt extension

尝试解析为 double;非数字或 null 返回 null。
toInt() → int?

Available on String?, provided by the StringExt extension

尝试解析为 int;非整数或 null 返回 null。