开发者

Help Defining RegEx to Capture Line Definition from INI file

Need help defining an expression to capture the four numerics per line that define the lines on a map.

59.684 -4.251 59.575 -5.576
59.575 -5.576 59.437 -6.899
59.437 -6.899 59.27 -8.218
-7.346 23.196 -7.409 23.233
-7.409 23.233 -7.46 23.285
-7.46 23.285 -7.495 23.349
-7.495 23.349 -7.51 23.42
9.172 39.362 9.134 39
9.134 39.288 9.087 39.219
9.087 39.219 9.03开发者_StackOverflow中文版2 39.155
9.032 39.155 8.97 39.099
8.97 39.099 8.901 39

Thanks,

Dave


(?<column1>\S+) (?<column2>\S+) (?<column3>\S+) (?<column4>\S+)

You can run that expression on every line and it will extract the values between spaces into four named capturing groups.

The <columnN> parts are the names of the groups you're capturing. You refer to them as column1, column2, etc.


You don't need regular expressions for that. Untested:

Using sr As New StreamReader("myFile.txt")
    Do
        Dim line = sr.ReadLine()
        If line Is Nothing Then Exit Do

        Dim values = line.Split()
        Dim x1 = Double.Parse(values(0), CultureInfo.InvariantCulture)
        Dim y1 = Double.Parse(values(1), CultureInfo.InvariantCulture)
        Dim x2 = Double.Parse(values(2), CultureInfo.InvariantCulture)
        Dim y2 = Double.Parse(values(3), CultureInfo.InvariantCulture)

        ' do something with these values '

    Loop
End Using


Use regex.matches with the string "(\S*[\d\.]+)" iterate through the returned MatchColection and the value will have the string you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜