C# 子串提取问题
我有这样的文本....
======== 1079.tif
Image Description : Vexcel-UCD-Level-3
------------------
CAM_ID: UCD-SU-1-0018 [5]
RECORD_GUID: 64763E99-3573-43AD-995B-8A07E3FE2BE3
IMG_NO: 1079
CAPTURE_TIME: 2004/03/15 02:07:17.641
IMG_TYPE: High resolution multi channel RGBI
ROTATION: 0 [degrees]
--- Inner Orientation ---------------
PRINCIPLE_DISTANCE: 101.400 [mm]
PRINCIPLE_POINT_X: 0.000 [mm]
PRINCIPLE_POINT_Y: 0.180 [mm]
PIXEL_SIZE_WIDTH: 9.000 [microns]
PIXEL_SIZE_HEIGTH: 9.000 [microns]
SENSOR_AREA_WIDTH: 103.500 [mm]
SENSOR_AREA_HEIGHT: 67.500 [mm]
-------------------------------------
--- Custom Meta Data ----------------
FMS No: 1079
Date: 070912
Time: 122005
Project: QOM
Area: QANAVAT
Line No: 11
Segment No: 1
Waypoint No: 17
WGS84 Latitude: N34.559857
WGS84 Longitude: E050.760726
WGS84 Altitude [m]: 1719.1
Pos Solution: GPS
Track [degree]: 271
Midpulse correction [s]: 0.00086
-------------------------------------
======== 1080vv.TIF
Image Description : Vexcel-UCD-Level-3
------------------
CAM_ID: UCD-SU-1-0018 [5]
RECORD_GUID: 64763E99-3573-43AD-995B-8A07E3FE2BE3
IMG_NO: 1080
CAPTURE_TIME: 2004/03/15 02:07:19.974
IMG_TYPE: High resolution multi channel RGBI
ROTATION: 0 [degrees]
--- Inner Orientation ---------------
PRINCIPLE_DISTANCE: 101.400 [mm]
PRINCIPLE_POINT_X: 0.000 [mm]
PRINCIPLE_POINT_Y: 0.180 [mm]
PIXEL_SIZE_WIDTH: 9.000 [microns]
PIXEL_SIZE_HEIGTH: 9.000 [microns]
SENSOR_AREA_WIDTH: 103.500 [mm]
SENSOR_AREA_HEIGHT: 67.500 [mm]
-------------------------------------
--- Custom Meta Data ----------------
FMS No: 1080
Date: 070912
Time: 122008
Project: QOM
Area: QANAVAT
Line No: 11
Segment No: 1
Waypoint No: 16
WGS84 Latitude: N34.559901
WGS84 Longitude: E050.758750
WGS84 Altitude [m]: 1717.9
Pos Solution: GPS
Track [degree]: 272
Midpulse correction [s]: 0.00086
-------------------------------------
如您所见,它有一个循环,该循环重复
我需要编写一个 C# 程序以从我的 txt 文件中提取所有这些类型的子字符串的
"1080"
"Longitude: E050.758750."
"Latitude : N34.559901."
[m]: 1717.9"
信息,有谁可以帮助我吗? ????
谢谢
i have a text like this ....
======== 1079.tif
Image Description : Vexcel-UCD-Level-3
------------------
CAM_ID: UCD-SU-1-0018 [5]
RECORD_GUID: 64763E99-3573-43AD-995B-8A07E3FE2BE3
IMG_NO: 1079
CAPTURE_TIME: 2004/03/15 02:07:17.641
IMG_TYPE: High resolution multi channel RGBI
ROTATION: 0 [degrees]
--- Inner Orientation ---------------
PRINCIPLE_DISTANCE: 101.400 [mm]
PRINCIPLE_POINT_X: 0.000 [mm]
PRINCIPLE_POINT_Y: 0.180 [mm]
PIXEL_SIZE_WIDTH: 9.000 [microns]
PIXEL_SIZE_HEIGTH: 9.000 [microns]
SENSOR_AREA_WIDTH: 103.500 [mm]
SENSOR_AREA_HEIGHT: 67.500 [mm]
-------------------------------------
--- Custom Meta Data ----------------
FMS No: 1079
Date: 070912
Time: 122005
Project: QOM
Area: QANAVAT
Line No: 11
Segment No: 1
Waypoint No: 17
WGS84 Latitude: N34.559857
WGS84 Longitude: E050.760726
WGS84 Altitude [m]: 1719.1
Pos Solution: GPS
Track [degree]: 271
Midpulse correction [s]: 0.00086
-------------------------------------
======== 1080vv.TIF
Image Description : Vexcel-UCD-Level-3
------------------
CAM_ID: UCD-SU-1-0018 [5]
RECORD_GUID: 64763E99-3573-43AD-995B-8A07E3FE2BE3
IMG_NO: 1080
CAPTURE_TIME: 2004/03/15 02:07:19.974
IMG_TYPE: High resolution multi channel RGBI
ROTATION: 0 [degrees]
--- Inner Orientation ---------------
PRINCIPLE_DISTANCE: 101.400 [mm]
PRINCIPLE_POINT_X: 0.000 [mm]
PRINCIPLE_POINT_Y: 0.180 [mm]
PIXEL_SIZE_WIDTH: 9.000 [microns]
PIXEL_SIZE_HEIGTH: 9.000 [microns]
SENSOR_AREA_WIDTH: 103.500 [mm]
SENSOR_AREA_HEIGHT: 67.500 [mm]
-------------------------------------
--- Custom Meta Data ----------------
FMS No: 1080
Date: 070912
Time: 122008
Project: QOM
Area: QANAVAT
Line No: 11
Segment No: 1
Waypoint No: 16
WGS84 Latitude: N34.559901
WGS84 Longitude: E050.758750
WGS84 Altitude [m]: 1717.9
Pos Solution: GPS
Track [degree]: 272
Midpulse correction [s]: 0.00086
-------------------------------------
as you can see it has a loop that repeats the information
i need to write a C# program to extract all these kind of substrings from my txt file
"1080"
"Longitude: E050.758750."
"Latitude : N34.559901."
[m]: 1717.9"
is there any one who can help me in this ????
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那些“..”部分可能是在翻译中丢失的 CR、LF 行结尾。
显而易见的答案是使用正则表达式 (RegEx),但您可能需要通过恢复行并仅从某些行中提取内容来进行一些预处理。我认为您的结果组来自 1“行”是一个条件。特别是“1080”值很容易不匹配。
当您需要正则表达式方面的帮助时请回复。
经过 Lasse 精彩的编辑后,问题变得更加清晰了。
通过查看数据,我想说您实际上并不需要 RegEx,但您可以一次处理 1 行数据并使用
line.StartsWith(...)
对它们进行分类。当您找到StartsWith("====")
的行时,您就喜欢“记录”的结束+开始。Those ".." sections probably are CR,LF line endings that got lost in translation somewhere.
The obvious answer is to use Regular Expressions (RegEx), but you may want to pre-process a little by restoring the lines and extract stuff from certain lines only. I gather that it is a condition that your result groups are from 1 'line'. Especially that "1080" value could be mis-matched easily.
Post back when you need help with your regexes.
After Lasse's fantastic Edit, the problem becomes a little clearer.
By looking at the data I would say you don't really need RegEx, but you can process the data 1 line at a time and classify them with
line.StartsWith(...)
. When you find a line thatStartsWith("====")
you have fond the end+start of a 'record'.正则表达式可能是执行此操作的好方法,但由于我不太擅长,请尝试以下操作:
我假设这就是你想要的。
有一些代码重复用于检查数组中是否有第二个值,但您可以自己改进
Regex are probably a good way to do this, but since i'm not ver good at it, try this:
I'm asuming that this is what you want.
Ther is some code duplication for checking there is a 2nd vlaue in the aray, but you can make that better your self