正则表达式:Replace的用法,两个点转一个点
我现在的数字:
113:21:57.56086E
我想转成
113.2157.56086E
我现在用下面这个正则,结果就有了两个小数点,如何能把后面一个取消掉呢?
string s = "23:07:33.09156N,113:21:57.56086E ";
string strResult = Regex.Replace(s, @ "(? <Degree> \d{2,3}):(? <Minute> \d{2}):(? <Second> [\.\d]{1,8})(? <ID> [NEWSnews]?) ",
@ "$1.$2$3$4 ");
if (strResult == null)
{
return;
}
MessageBox.Show(strResult);
------解决方案--------------------找到匹配后用IndexOf把第二个替换吧
------解决方案--------------------string s = "23:07:33.09156N,113:21:57.56086E ";
s=s.Replace( ". ", " ");//看那点多余 先去了不就OK了
s=Regex.Replace(s,@ "(\d+):(\d+):([\d.]+)[A-Z] ", "$1.$2$3 ");