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

Shu*_*nov 2 dart flutter

大家好,我正在尝试删除或隐藏 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,
          ),
        ),
Run Code Online (Sandbox Code Playgroud)

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

Ket*_*eke 6

使用substring方法:

main() {
  print("12:00 AM".substring(0,5));
}
Run Code Online (Sandbox Code Playgroud)

或使用replaceAll方法:

main() {
  print("12:00 AM".replaceAll("AM","").replaceAll("PM",""));
}
Run Code Online (Sandbox Code Playgroud)

使用正则表达式:

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

  • 欢迎,请考虑接受答案:) (3认同)