如何从列表中删除字符串的最后一个字母?镖

大家好,我正在尝试删除或隐藏 List 中的最后一个字母

有什么可能的方法吗?

Text(list[i].name,
          style: GoogleFonts.poppins(
              fontWeight: FontWeight.w400,
              color:
              list[i].isBook == "0"
                  ? selectedTimingSlot[i] ? WHITE : BLACK
                  : Colors.grey.withOpacity(0.5),
              fontSize: 15,
          ),
        ),

**Above code shows= "12:00 AM" I need to hide or remove "AM"**

回答

使用substring方法:

main() {
  print("12:00 AM".substring(0,5));
}

或使用replaceAll方法:

main() {
  print("12:00 AM".replaceAll("AM","").replaceAll("PM",""));
}

使用正则表达式:

main() {
  var regex = new RegExp(r'[a-zA-Z]');
  print("02:00 AM".replaceAll(regex,""));
}

  • Welcome, do consider accepting the answer 🙂

以上是如何从列表中删除字符串的最后一个字母?镖的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>