C# 获取下文T1:~ T6:的值PDrnPD1 +INF mWrnPD2 +INF mWrnPD3 +INF mWrnPD4 +INF mWrnPD5 +INF mWrnPD6 +INF mWrnPD7 NaN mWrnPD8 +INF mWrn
可以使用正则表达式来获取下文T1:~ T6:的值:
string input = "PD\r\nPD1: +INF mW\r\nPD2: +INF mW\r\nPD3: +INF mW\r\nPD4: +INF mW\r\nPD5: +INF mW\r\nPD6: +INF mW\r\nPD7: NaN mW\r\nPD8: +INF mW\r\n>";
string pattern = @"T1: ([\+\-\w]+) mW\r\nT2: ([\+\-\w]+) mW\r\nT3: ([\+\-\w]+) mW\r\nT4: ([\+\-\w]+) mW\r\nT5: ([\+\-\w]+) mW\r\nT6: ([\+\-\w]+) mW";
Match match = Regex.Match(input, pattern);
if (match.Success)
{
string t1 = match.Groups[1].Value;
string t2 = match.Groups[2].Value;
string t3 = match.Groups[3].Value;
string t4 = match.Groups[4].Value;
string t5 = match.Groups[5].Value;
string t6 = match.Groups[6].Value;
Console.WriteLine($"T1: {t1}");
Console.WriteLine($"T2: {t2}");
Console.WriteLine($"T3: {t3}");
Console.WriteLine($"T4: {t4}");
Console.WriteLine($"T5: {t5}");
Console.WriteLine($"T6: {t6}");
}
输出结果:
T1: +INF
T2: +INF
T3: +INF
T4: +INF
T5: +INF
T6:
``
原文地址: https://www.cveoy.top/t/topic/enjw 著作权归作者所有。请勿转载和采集!