【问题标题】:How to remove a character from string and concatinate it in Dart | Flutter如何从字符串中删除一个字符并在 Dart 中连接它 |扑
【发布时间】:2021-04-19 05:22:17
【问题描述】:

我有两个变量

String firstInput = "1.1.5";
String secondInput = "1.1.6";

从这里我想要输出 firstOutput = 115 secondOutput = 116 如何从字符串中删除点并连接仍然作为一个变量?

【问题讨论】:

    标签: dart


    【解决方案1】:

    您可以使用replaceAll 方法。
    它看起来像String out = firstInput.replaceAll(".","");

    【讨论】:

      【解决方案2】:

      您也可以使用replaceAllRE,如下所示

      void main(){
        final myString = '1.3.4.6.6';
        String withoutDots = myString.replaceAll(RegExp('\\.'), ''); "Here \\ is used to as esc char"
        print(withoutDots); // prints 13466
      
      }
      

      【讨论】:

        猜你喜欢
        • 2014-07-30
        • 1970-01-01
        • 1970-01-01
        • 2013-03-17
        • 2023-01-07
        • 2012-03-27
        • 1970-01-01
        • 2021-03-26
        • 2020-01-10
        相关资源
        最近更新 更多