本文介绍了如何格式化插入字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要格式字符串,例如秒前发送%d ,哈利喜欢%s,我认为%1 $ s喜欢%2 $ s 。这些可以在Android中实现,但是我不怎么在Flutter的Dart中实现。
I need format string like "Send %d seconds ago", "Harry like %s", "I think %1$s like %2$s". These can be implemented in Android, but i don't how to implement in Dart of Flutter.
推荐答案Dart支持字符串插值
Dart supports string interpolation
var seconds = 5; print("Send $seconds seconds ago"); var harryLikes = 'Silvia'; var otherName = 'Erik'; var otherLikes = 'Chess'; print("Harry like $harryLikes"); print("I think $otherName like $otherLikes");也可以使用 $ {...}
Also more complex expressions can be embedded with ${...}
print('Calc 3 + 5 = ${3 + 5}');数字类型和 intl 软件包提供格式化数字和日期的更多方法。
The number types and the intl package provide more methods to format numbers and dates.
例如参见
- www.dartdocs/documentation/intl/latest/ intl / NumberFormat-class.html
- dart的货币格式
- www.dartdocs/documentation/intl/latest/intl/NumberFormat-class.html
- Currency format in dart
更多推荐
如何格式化插入字符串
发布评论