【发布时间】:2019-02-26 10:17:59
【问题描述】:
我有一个字符串,我想从中删除数字之间的空格:
string test = "Some Words 1 2 3 4";
string result = Regex.Replace(test, @"(\d)\s(\d)", @"$1$2");
预期/期望的结果是:
"Some Words 1234"
但我检索到以下内容:
"Some Words 12 34"
我在这里做错了什么?
更多示例:
Input: "Some Words That Should not be replaced 12 9 123 4 12"
Output: "Some Words That Should not be replaced 129123412"
Input: "test 9 8"
Output: "test 98"
Input: "t e s t 9 8"
Output: "t e s t 98"
Input: "Another 12 000"
Output: "Another 12000"
【问题讨论】:
-
为了好玩,here 是一个无正则表达式的解决方案。我认为正则表达式是更好的解决方案。