1 (edited by mathmathou 2015-11-05 02:56:33)

Topic: Parsing text

Hello Dmitry and all MVD fans,


Thanks to the forum and the onlinehelp, I was able to open and read any kind of files (txt, and others as well).


I also found a way to select a specific line in a file.


What I did not find is how to break that line into pieces according to it's structure.


I mainly focused on the SplitString and Trim functions (String Routines), but did not quite get what I was expecting.


Any idea for me ?

Examples :


How could I extract  Some product name from the line  <ProductName VALUE="Some product name"/> ?


Or, how could I extract the x first characters in a string like :
fb63882b-4498-4215-bfa0-b2eef88eb3f7 = Default Lights and Shaders


Or, from character x to character y ?


Thanks in advance and have a good day

Cheers

Math

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Parsing text

Example, how to extract Some product name

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
    sStart, sEnd: string;
    sSource: string;
begin
    sSource := '<ProductName VALUE="Some product name"/> ?';
    sStart := '<ProductName VALUE="';
    sEnd := '"/> ?';

    Form1.Edit1.Text := Copy(sSource, Length(sStart)+1, Length(sSource) - Length(sStart)-Length(sEnd) );
end;
Dmitry.

Re: Parsing text

Hello Dmitry,

Thank you for your answer !! That does exactly the trick !!

Thanks again

Math

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor