111,098
社区成员




- string str="气压:097.71kPa 气温:023.46度 湿温:023.5度 湿度:026.1%RH 露点:002.9度";
string s = "气压:097.71kPa 气温:023.46度 湿温:023.5度 湿度:026.1%RH 露点:002.9度";
string pattern = @"([-]*)[0]*([\d]+.[\d]*)";
MatchCollection mc = Regex.Matches(s, pattern);
foreach (Match m in mc)
{
Console.WriteLine($"{m.Groups[1].Value}{m.Groups[2].Value}");
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
List<double> nums = GetNumsList("气压:097.71kPa 气温:023.46度 湿温:023.5度 湿度:026.1%RH 露点:002.9度");
foreach (double num in nums)
{
Console.WriteLine(num);
}
Console.ReadKey(true);
}
static List<double> GetNumsList(string str)
{
List<double> list = new List<double>();
List<char> nums = new List<char>();
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= 48 && str[i] <= 57)
{
nums.Add(str[i]);
}
else if (str[i] == '.')
{
nums.Add(str[i]);
}
else
{
if (nums.Count > 0)
{
string num = new string(nums.ToArray());
list.Add(double.Parse(num));
nums.Clear();
}
}
}
return list;
}
}
}