C# 从下文获取T1:~T6:的数据 TEMPrnT1 2777rnT2 -23057rnT3 -23057rnT4 -23057rnT5 -23057rnT6 -23057rnT7 -23057rnT8 -23057rn
可以使用正则表达式来获取T1到T6的数据:
string input = "TEMP\r\nT1: 27.77\r\nT2: -230.57\r\nT3: -230.57\r\nT4: -230.57\r\nT5: -230.57\r\nT6: -230.57\r\nT7: -230.57\r\nT8: -230.57\r\n>";
string pattern = @"T[1-6]:\s*(-?\d+(?:\.\d+)?)";
MatchCollection matches = Regex.Matches(input, pattern);
foreach (Match match in matches)
{
string tValue = match.Groups[1].Value;
Console.WriteLine("T{0}: {1}", match.Index + 1, tValue);
}
输出结果为:
T1: 27.77
T2: -230.57
T3: -230.57
T4: -230.57
T5: -230.57
T6: -230.57
``
原文地址: https://www.cveoy.top/t/topic/emYO 著作权归作者所有。请勿转载和采集!