Question Reading a file and extract text

JaredNinja

New member
Joined
Aug 18, 2012
Messages
3
Programming Experience
5-10
Hi guys,

I need a bit of help. I'm trying to read a file as text, and extract 1 tiny piece. The file in question is a *.SOR file.

When opening the file in a text-editor, I'm able to find the piece of text that I need. Yet, to extract it from the file, you need a proper method. I've tried to split the file on all sorts of things but when I use my application on 10 different SOR files, theres always one that fails. My method is just too fragile.

I'm looking for a person that has the ultimate way of reading these files, and extracting the same bit of text each time (the label). A method that is stable and works each time.

I don't seem to be able to attach the files. Appreciate any help. If you have any further questions, shoot!
 
Last edited:
This might be a good start:

    Function Extract(ByVal file_content As String) As String
        Return System.Text.RegularExpressions.Regex.Match(
            System.Text.RegularExpressions.Regex.Replace(
                file_content, "Map.*GenParams.*GenParams.*BC..", ""),
            ".*SupParams").Value.Replace("SupParams", "").Trim
    End Function


Obviously, with only 2 cases as sample, it is impossible to guarantee it fits all or most of other situations. I hope it helps.
 
Thanks VBobCat!

That code seems to work (still testing). Yet, the trim function at the end does not work well. The final string is " NL-ZAN-GB-LOW-CA 48F .sor". So its not just normal spaces I guess. I think a regex that only allows common characters (numbers, letters, common signs) would do the trick.

ps: actually this forum shortens the string to a space before and after the label text, but in reality its much more.
 
Back
Top