シリアル ポート通信を介して文字列でデータを受信しています。その部分はうまく機能しています。データの形式は次のとおりです。
Distance run: 36in.
Direction in degrees: 275
Total of person founds:11
New Person found in:
Lat/Long: 18.38891, -66.12174
Date: 5/4/2013 Time: 19:13:35.0
Total of person founds:12
New Person found in:
Lat/Long: 18.38891, -66.12175
Date: 5/4/2013 Time: 19:13:37.0
Distance run: 15in.
Direction in degrees: 215
Total of person founds:13
New Person found in:
Lat/Long: 18.38891, -66.12174
Date: 5/4/2013 Time: 19:13:39.0
Distance run: 30in.
Direction in degrees: 180
しかし、これは、発見された人の各ブログ (緯度/経度、日付と時刻の位置を含む) の間で少し異なる可能性があります。
正規表現を試しましたが、うまく使用する方法がわかりません。数字だけを抽出する正規表現もあります。
var xnumbers = Regex.Split(strFileName, @"[^0-9\.\-]+").Where(c => c != "." && c.Trim() != "");
私が望むのは、たとえば距離走行の特定の値を抽出することです。最初の値は36インチで、それを保存するなどです。次に、方向の値を度で取得して別の変数に保存し、最後に緯度と経度を取得して別の変数に保存します。後でそのデータを使用してプロットするためのリストを作成するには、この値が必要です。私はすでに描画部分を持っています。
私はこれを試しました:
このパターンは、距離が 2 つの数値のみであるが、その値は 1 つまたは 3 つの数値である可能性があることのみを考慮していることを知っています (例: 走行距離: 1 インチまたは走行距離: 219 インチ)
string pattern = @"^Distance Run:(?<distance>.{2}),Direction in degrees:,(?<degress>. {3}),Lat/Long:(\+|\-)(?<latlong>.{18})$";
string distance = string.Empty;
string degrees = string.Empty;
string latlong = string.Empty;
Regex regex = new Regex(pattern);
if (regex.IsMatch(strFileName)) // strFileName is the string with the data
{
Match match = regex.Match(strFileName);
foreach (Capture capture in match.Groups["distance"].Captures)
distance = capture.Value;
foreach (Capture capture in match.Groups["degree"].Captures)
degrees = capture.Value;
foreach (Capture capture in match.Groups["Lat/Long"].Captures)
latlong = capture.Value;
}
しかし、機能していません。助けやアドバイスをいただければ幸いです。前もって感謝します。