dart:从 Flutter 中的文本拆分字符串

问题描述 投票:0回答:0

这是我的字符串。

"Buy Any Medium Cheese Crust Pizza Get 50% OFF on second pizza of same or lesser value.\r\n\r\nCode OPEN50\r\n\r\nT&C  -\r\nOffer is not valid on Margherita, Cheesy Murgh, Cheesy Spicy Chicken.\r\nOffer can be withdrawn without any prior notice. \r\nOffer cannot be clubbed with any other offer.\r\n\r\n"

我已经完成了一些编码,但它出错了

void main() {
  String input = "Get a  FREE Garlic Bread Sticks  on order.\r\n\r\nCode JAIPUR\r\n\r\nT&C  -\r\nOffer is valid for Jaipur Outlets only.\r\nOffer can be withdrawn without any prior notice. \r\nOffer cannot be clubbed with any other offer.";
List<String> split1 = input.split("\r\n\r\n");
  List<String> split2 = input.split("Code ");
  List<String> split3 = input.split("\r\n");
print("split1 $split1");
  print("split2 $split2");
  print("split3x` $split3");
// Output: ['abc', 'def456']
  var splited = [];
  splited = [{
    "desc":split1[0],
    "code":split2[1],
    "t&C":split3[2]
  }];
  print("\n----------------------------------------------\n");
  print("splited:: $splited");


}

你可以在这里看到我在 dartPad 上尝试,但我认为这是错误的。 https://dartpad.dev/?id=c2014eee1fc48065888cc6a4d5f485b7

我要这样分手

[
{
"desc":"Buy Any Medium Cheese Crust Pizza Get 50% OFF on second pizza of same or lesser value.",
"code":"OPEN50",
"t&c":[
        "Offer is not valid on Margherita, Cheesy Murgh, Cheesy Spicy Chicken.",
        "Offer can be withdrawn without any prior notice.",
        "Offer cannot be clubbed with any other offer."
      ]
}
]
dart angular-dart dart-html
© www.soinside.com 2019 - 2024. All rights reserved.