[英]Regex.Match throws FormatException
我正在使用UDP,現在正在捕獲從傳感器發出的信息。 我試圖僅從發送的信息中提取數字,即溫度,光和運動,並嘗試使用Regex實現該目的。 但是我得到一個FormatException,它指出:“其他信息:輸入字符串的格式不正確”。 這是代碼:
UdpClient udpClient = new UdpClient(1337);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0);
while (true)
{
for (int i = 0; i < 5000; i++)
{
Byte[] receive = udpClient.Receive(ref endPoint);
string receiveDat = Encoding.ASCII.GetString(receive);
string result = Regex.Match(receiveDat, @"\D+").Value;
Console.WriteLine(Int32.Parse(result));
Console.ReadLine();
}
}
如果要使用數字而不是非數字,則需要在正則表達式中使用小寫\\d
。 大寫\\D
僅匹配非數字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.