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 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

你可能感兴趣的:(iOS,Android,移动端,flutter)