java Split text包含字符串列表中的数字 1 年,3 月 Questions & Answers 63 我有数字,想用特殊字符将其拆分为字符串列表,而不删除特殊字符,比如拆分 1,245.00 to 1 , 245 . 00
# 1 楼答案 有多种选择。您可以使用边界(积分到@4castle),也可以使用向前看(积分到previous reply)和向后看 以下是三个可行的选项: String input = "1,245.00"; // look-ahead only Stream.of(input.split("(?=[,.])|(?<=[^\\d])")).forEach(System.out::println); System.out.println(); // Boundary Stream.of(input.split("\\b")).forEach(System.out::println); System.out.println(); // Mix of look-behind and look-ahead Stream.of(input.split("(?![\\d])|(?<=[^\\d])")).forEach(System.out::println); 全部打印在一起: 1 , 245 . 00 1 , 245 . 00 1 , 245 . 00
# 1 楼答案
有多种选择。您可以使用边界(积分到@4castle),也可以使用向前看(积分到previous reply)和向后看
以下是三个可行的选项:
全部打印在一起: