gpt4 book ai didi

flutter - 为什么在Dart中执行“方法级联”时出现此错误?

转载 作者:行者123 更新时间:2023-12-03 04:43:00 24 4
gpt4 key购买 nike

我有一个单行代码,该代码删除尾随空格和前导空格,并且还用单个空格替换了中间的多个空格。 (来自字符串)

value = value..trim()..split(" +")..join(" ");
但是我收到以下错误。
The method 'join' isn't defined for the type 'String'.
Try correcting the name to the name of an existing method, or defining a method named 'join'.(dartundefined_method)
我做错了什么?

最佳答案

您不需要在那里的级联表示法:

value = value.split(' ').where((x) => x.isNotEmpty).map((x) => x.trim()).join(" ")

关于flutter - 为什么在Dart中执行“方法级联”时出现此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62824915/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com