示例
0.00000000到0.30000000000 需要转变为 0-0.3
65465.12100四角连续908.34500焊接,焊接100.207.254小固定板
需要转变为
65465.121四角连续908.345焊接,焊接100.207.254小固定板
public static string Split(string s)
{
try
{
if (s.Length <= 1)
{
return s;
}
ArrayList result = new ArrayList();
string addStr = "";//存放容器
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");
string last = "";
string now = "";
int i = 0;
foreach (char c in s)
{
i++;
string Str_c = c.ToString();
if (string.IsNullOrEmpty(addStr))
{
addStr += Str_c;
continue;
}
if (Str_c == ".")
{
now = "数字";
}
else
{
now = reg1.IsMatch(Str_c) ? "数字" : "汉字";
}
if (last == "")
{
last = now;
}
if (now != last)
{
result.Add(addStr);
addStr = "";
}
last = now;
addStr += c.ToString();
//最后一位直接加进去数组
if (i == s.Length)
{
result.Add(addStr);
addStr = "";
}
}
string res = "";
foreach (string s1 in result)
{
if (reg1.IsMatch(s1))
{
res += removeFloat(s1);
}
else
{
res += s1;
}
}
return res;
}
catch (Exception e)
{
return s;
}
}
public static string removeFloat(string qInfoQcDocInfoBody)
{
string content = qInfoQcDocInfoBody;
try
{
Match m;
m = Regex.Match(content, @"\d*\.\d*|0\.\d*[1-9]\d*$");
while (m.Success)
{
string s = m.Groups[0] + "";
float url = JsonToDataTable.ToFloat(m.Groups[0], 0);
if (url != 0)
{
content = content.Replace(m.Groups[0] + "", url + "");
}
else if (url == 0 && s.Length > 1) //特殊情况1 0.00不等于0 需要处理0.00为0
{
content = content.Replace(m.Groups[0] + "", url + "");
}
m = m.NextMatch();
}
}
catch (Exception e)
{
return qInfoQcDocInfoBody;
}
return content;
}