views:

628

answers:

3

hi ....

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

A: 

Have you tried yet? No-one here is going to do it for you, but everyone is more than happy to help you if you attempt it and get stuck.

Ian Devlin
This should be a comment, not an answer.
Kyle Rozendo
Yes, you are right. My apologies.
Ian Devlin
Thats right, in the future you can post it as a code golf type challenge, and you'll have professors jumping to answer.
Yuriy Faktorovich
thats right lan Devlin :)
anishmarokey
thank you very much let me explane more ... these informations hase been extracted from air pictures that will be use in geo metric issuesthese are the metadata informations of that pictures that has been extractedwith some programes like "exiftool"and has been saved in to a text file because an unwanted annomally i have to rechek the coardinates of each pictures whith its name in orderr to find its real location in the gride...and im not a very handfull in C# programing but i need help to solve this problem all info's will be extract in to onr txt filethanks
+1  A: 

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 that StartsWith("====") you have fond the end+start of a 'record'.

Henk Holterman
A: 

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.

    public ObjectOfMyFile ParseFile(string fileContent)
    {
        ObjectOfMyFile objectOfMyFile = new ObjectOfMyFile();
        string[] contentLines = fileContent.Split(new[] { Environment.NewLine },
                                                  StringSplitOptions.RemoveEmptyEntries);

        for (int i = 0; i < contentLines.Length; i++)
        {
            string contentLine = contentLines[i];

            if (contentLine.StartsWith("FMS No", StringComparison.OrdinalIgnoreCase))
            {
                string[] fmsNo = SplitByColon(contentLine);
                if (fmsNo.Length == 2)
                {
                    objectOfMyFile.Longitudes.Add(fmsNo[1].Trim());
                }

                continue;
            }

            if (contentLine.IndexOf("WGS84 Longitude", StringComparison.OrdinalIgnoreCase) > -1)
            {
                string[] longitudeKeyValue = SplitByColon(contentLine);
                if (longitudeKeyValue.Length == 2)
                {
                    objectOfMyFile.Longitudes.Add(longitudeKeyValue[1].Trim());
                }

                continue;
            }
        }

        return objectOfMyFile;
    }

    public string[] SplitByColon(string valueToSplit)
    {
        return valueToSplit.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
    }

    public class ObjectOfMyFile
    {
        public ObjectOfMyFile()
        {
            Longitudes = new List<string>();
            FmsNos = new List<string>();
        }
        public List<string> Longitudes { get; private set; }
        public List<string> FmsNos { get; private set; }
        // Etc...
    }
}

Ther is some code duplication for checking there is a 2nd vlaue in the aray, but you can make that better your self

Jeroen
thank you very much jeroenbut im a bit confuse i cant underestand the code exactly would you mind please explane it little more and ...how can iget the out put from it well im a bit new C# programing i used some kind of like this; but it only could extract the info from first line
i wrote some kind of program that:1-open the txt file with "open file dialog"2-with the method substring between two string s i extracted strings for the first line 3-show it in a text box4-and save it with savefiledialog in to another txt filebut it was not what i want i need to extract all these info's that has benn looping reapetedly in the text file and i had no idea so i had to ask you
Have you tried reading the file and passing the content to this method. With the debugger you should be abble to figure out what is happing i asume.
Jeroen