可以使用正则表达式来获取下文 T1:~ T6:的值:/n/ncsharp/nstring 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>';/nstring pattern = @'T1: ([/+/-/w]+) mW//r//nT2: ([/+/-/w]+) mW//r//nT3: ([/+/-/w]+) mW//r//nT4: ([/+/-/w]+) mW//r//nT5: ([/+/-/w]+) mW//r//nT6: ([/+/-/w]+) mW';/nMatch match = Regex.Match(input, pattern);/nif (match.Success)/n{/n string t1 = match.Groups[1].Value;/n string t2 = match.Groups[2].Value;/n string t3 = match.Groups[3].Value;/n string t4 = match.Groups[4].Value;/n string t5 = match.Groups[5].Value;/n string t6 = match.Groups[6].Value;/n Console.WriteLine($'T1: {t1}');/n Console.WriteLine($'T2: {t2}');/n Console.WriteLine($'T3: {t3}');/n Console.WriteLine($'T4: {t4}');/n Console.WriteLine($'T5: {t5}');/n Console.WriteLine($'T6: {t6}');/n}/n/n/n输出结果:/n/n/nT1: +INF/nT2: +INF/nT3: +INF/nT4: +INF/nT5: +INF/nT6: /n

C# 使用正则表达式提取文本中的 T1 到 T6 的值

原文地址: https://www.cveoy.top/t/topic/gCfC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录