I am working on creating a windows form application and I have a problem. I am reading data from a serial port.
string RxString = serialPort1. ReadExisting (); It works fine, but now what I want to do is remove the value from my RxString and puts them in my string array. This RxString format:
GPS: 050.1347, N, 00007.3612, WMAG: +231 \ r \ n More data Is added because it repeats itself, the number varies from the serial port but remains the same length, and changes in + -. I want to place the numbers between the GPS: and, the number between a string array, n in n, and, in the second string array, and finally the number between + and \ r \ n in another string array .
How would I go about doing this?
OK, Regex Solution:
String Pattern = @ " ^ GPS: (? Lt; gps>; {8}), n, (? & Lt; n & gt;., {10}), wmag: (\ + | \ -) (? & Amp; LT; wmag>. {3}) \\ r \\ $ n "; String gps = string Empty; String n = string Empty; String wmag = string.Empty; String input = @ "GPS: 050.1347, n, 00007.3612, WMAG: +231 \ r \ n"; Reggae Reggae = new Reggae (Pattern); If (regex.ismatch (input)) match {match = regex.match (input); External Capture Capture Group ("GPS" in Capture. Capture) GPS = Capture. Value; Capture Capture Capture in Group (Group "[" "N"]) Capture N = Capture. Value; Capture Capture Capture in Group ("wmag"]. Capture) wmag = capture.Value; } Console. Type ("GPS:"); Console.WriteLine (GPS); Console Type ("N:"); Console.WriteLine (N); Console Write ("WMAG:"); Console.WriteLine (wmag); Console.ReadLine ();
No comments:
Post a Comment