Flutter String格式化

请看原文: http://tryenough.com/flutter-stringformat

在Android和iOS平台都有相应的方法进行字符串的格式化,但是在flutter中却没有直接提供

在flutter上可以借助一个插件来进行格式化:

sprintf

import 'package:sprintf/sprintf.dart';

例子

import 'package:sprintf/sprintf.dart';

void main() {
    print(sprintf("%04i", [-42]));
    print(sprintf("%s %s", ["Hello", "World"]));
    print(sprintf("%#04x", [10]));

    double seconds = 5.0;
    String name = 'Dilki';
    List<String> pets = ['Cats', 'Dogs'];

    String sentence1 = sprintf('Sends %2.2f seconds ago.', [seconds]);
    String sentence2 = sprintf('Harry likes %s, I think %s likes %s.', [pets[0], name, pets[1]]);

    print(sentence1);
    print(sentence2);

  }

请看原文: http://tryenough.com/flutter-stringformat

    原文作者:roundstones
    原文地址: https://segmentfault.com/a/1190000018809365
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞