我的flutter应用程序显示从第三方获取的描述字符串,因此这些描述可能已经带有省略号以引导故事继续前进,但api仅获取了大约7行左右的描述。
我希望每个描述都包含省略号,但又不想在已经包含省略号的字符串中添加省略号。
我想把这个
将每个帐户所有者的头像扫描为
进入此
以...的方式扫描每个帐户持有人的头像
但是如果原件已经包含该省略号,则应将其跳过。
答案 0 :(得分:1)
String input = 'your string';
if (!input.endsWith('...')) {
input += '...';
}
这里的键是String.endsWith()
,这是知道内容是否已经以省略号结尾的最简单方法。
答案 1 :(得分:1)
@greyaurora的回答得到增强
my data...
...
(3个点)与…
(1个字符的省略号)void main() {
String input = 'your string';
String trimmed = input.trim();
if (!trimmed.endsWith('...') && !trimmed.endsWith('…')) {
trimmed += '…';
}
print('hello ${trimmed}');
}