【问题标题】:Regex replace for swapping order of numbers in a string正则表达式替换字符串中数字的顺序
【发布时间】:2015-06-15 14:00:49
【问题描述】:

我把这个交换列表中数字的 linq 查询放在一起。我想知道是否有一种使用正则表达式的优雅方式。

var str = " <gml:coordinates>36.230968,21.971054 36.633873,19.144154 38.007656,19.423254 37.606049,22.303988 36.230968,21.971054</gml:coordinates>";
var test = string.Format("<gml:coordinates>{0}</gml:coordinates>", string.Join(" ", Regex.Match(str, "<gml:coordinates>(.*)</gml:coordinates>").Groups[1].Value.Split(' ').Select(d => string.Join(",", d.Split(',').Reverse()))));
//<gml:coordinates>21.971054,36.230968 19.144154,36.633873 19.423254,38.007656 22.303988,37.606049 21.971054,36.230968</gml:coordinates>

【问题讨论】:

    标签: c# regex linq


    【解决方案1】:

    以下应该有效:

    Regex.Replace(str, @"([\d.]*),([\d.]*)", "$2,$1")
    

    【讨论】:

      猜你喜欢
      • 2012-04-26
      • 2018-07-13
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 1970-01-01
      相关资源
      最近更新 更多