Delphi - Custom String Manipulation

I have a problem in Delphi7. My application creates mpg video files according to ie naming convention

\ 000_A_Title_YYYY-MM-DD_HH mm ss_Index.mpg

The following rules apply to this file name:

000 is a video sequence. It increases each time you press the stop button.

A (or B, C, D) indicates the recording camera - therefore, video files are associated with four video streams that play simultaneously.

Title - a string of variable length. In my application, it cannot contain _ .

YYYY-MM-DD_HH-mm-ss - start time of the video sequence (not one file)

Index - the index of the index based on zero and increases within 1 video sequence. That is, video files no more than 15 minutes, as soon as this is achieved, a new video file is launched with the same serial number, but followed by an index. Using this, we can calculate the actual start time of the file (Filename decoded time + 15*Index)

With this method, my application can retrieve the start time of recording a video file.

Now we have one more requirement for processing arbitrarily named video files. The only thing I know for sure is somewhere in the file name YHY-MM-DD HH-mm-ss.

How can I allow the user to specify a file name convention for the files that he imports? Something like Regular Expressions? I understand that there must be a template for the naming scheme.

So, if the user enters ?_(Camera)_*_YYYY-MM-DD_HH-mm-ss_(Index).mpg into the text box, how would I get the start time? Is there a better solution? Or should I just handle every opportunity when we come to them?

(I know that this is probably not the best way to deal with such a problem, but we cannot change the problem - new video files are recorded by another company)

+4
source share
3 answers

I'm not sure if you are trying to parse user input into components? (Camera) * _YYYY-MM-DD_HH-mm-ss_ (Index) .mpg`, but if you just try to capture the date and time something like this, the date is in group 1, the time in group 2

(\d{4}-\d{2}-\d{2})_(d{2}-\d{2}-\d{2})

Otherwise, not sure what you are trying to do.

+4
source

Perhaps you can use the underscore "_" as your position indicator, as you are smarter not to allow them in the header.

In your example file name convention:

 ?_(Camera)_*_YYYY-MM-DD_HH-mm-ss_(Index).mpg 

you can parse this string specified by the user to see that the date YYYY-MM-DD is always between the 3rd and 4th underscores and the time HH-mm-ss is between the 4th and 5th.

Then it becomes a simple matter when you get the actual file names following this convention to find the third underscore and know that the date and time follows it.

+3
source

If you need 24/7 phone calls, you should upgrade to the RegEx thing and allow the user to freely enter cryptography into TEdit.

If you want happy users and a good night's sleep, then be creative and drop the boring RegEx approach. Create your own decoder file using the Angry Bird approach.

Here is an idea:

  • Create several birds with different characters associated with the string.
  • Let the user select and suit these birds.
  • Performing custom string processing.

Code example:

 program AngryBirdFilenameDecoder; {$APPTYPE CONSOLE} uses SysUtils; procedure PerformEatUntilDash(var aStr: String); begin if Pos('-', aStr) > 0 then Delete(aStr, 1, Pos('-', aStr)); WriteLn(':-{ > ' + aStr); end; procedure PerformEatUntilUnderscore(var aStr: String); begin if Pos('_', aStr) > 0 then Delete(aStr, 1, Pos('_', aStr)); WriteLn(':-/ > ' + aStr); end; function FetchDate(var aStr: String): String; begin Result := Copy(aStr, 1, 10); Delete(aStr, 1, 10); WriteLn(':-) > ' + aStr); end; var i: Integer; FileName: String; TempFileName: String; SelectedBirds: String; MyDate: String; begin Write('Enter a filename to decode (eg. ''01-ThisIsAText-Img_01-Date_2011-03-08.png''): '); ReadLn(FileName); if FileName = '' then FileName := '01-ThisIsAText-Img_01-Date_2011-03-08.png'; repeat TempFileName := FileName; WriteLn('Now, select some birds:'); WriteLn('Bird No.1 :-{ ==> I''ll eat letters until I find a dash (-)'); WriteLn('Bird No.2 :-/ ==> I''ll eat letters until I find a underscore (_)'); WriteLn('Bird No.3 :-) ==> I''ll remember the date before I eat it'); WriteLn; Write('Chose your birds: (eg. 112123):'); ReadLn(SelectedBirds); if SelectedBirds = '' then SelectedBirds := '112123'; for i := 1 to Length(SelectedBirds) do case SelectedBirds[i] of '1': PerformEatUntilDash(TempFileName); '2': PerformEatUntilUnderscore(TempFileName); '3': MyDate := FetchDate(TempFileName); end; WriteLn('Bird No.3 found this date: ' + MyDate); WriteLn; WriteLn; Write('Check filename with some other birds? (Y/N): '); ReadLn(SelectedBirds); until (Length(SelectedBirds)=0) or (Uppercase(SelectedBirds[1])<>'Y'); end. 

When you do this in Delphi with a GUI, you will add more birds and, of course, check more. And find nice bird glyphs.

Use two lists. One on the left with all possible birds, and one on the right with all the selected birds. Drag the birds from left to right. Rearrange (and delete) the birds in the list on the right.

The user should be able to test the installation by entering the file name and see the result of the process. Internally, you store the script with counters, etc.

+1
source

Source: https://habr.com/ru/post/1342700/


All Articles