【问题标题】:(Flutter/Dart) Replace all parentheses with html tags parentheses in string?(Flutter/Dart)用字符串中的html标签括号替换所有括号?
【发布时间】:2018-10-20 18:28:55
【问题描述】:

我需要用 html 标签替换使用某些特殊字符的括号。

例子:

“''test''”变成“test

"//例子//"变成"例子"

如何在 Flutter 中使用 Dart 语言实现这一点?

【问题讨论】:

    标签: string mobile dart flutter


    【解决方案1】:

    使用replaceFirst 可能会让你想要。

    main() {
      String test = "\"test\" //Example//";
    
      final Map<String, List<String>> map = {
        "\"": ["< b >", "< \/b >"],
        "//": ["< i >", "< /i >"]
      };
    
      map.forEach((key, mapping) {
        test = test.replaceFirst(key, mapping[0]);
        test = test.replaceFirst(key, mapping[1]);
      });
    
      print(test);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-04
      • 1970-01-01
      • 2015-04-16
      • 2016-07-28
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多