Extract first line from a description field

If you made a script you can offer it to the others here, or ask help to improve it. You can also report here bugs & problems with existing scripts.
Post Reply
manolo7
Posts: 7
Joined: 2009-06-18 10:29:45

Extract first line from a description field

Post by manolo7 »

In the past I used the DESCRIPTION field to collect "Languages", "Country" and "Description". The data was stored in this field with the HTML tag I need. Now I organize the catalog in a different way and I need to move "Languages" and "Country" from this field to another, leaving the DESCRIPTION field with only original "Description" data.

My DESCRIPTION field looks like this:
<h3>Languages: </h3>English <h3>Country: </h3>USA
<h3>Description:</h3>Lorem ipsum dolor...
First line have a variable length, but always end with CR/LF followed by the "<h3>Description: </h3>" and can be easily extracted, but I don't know the script functions/procedures that can do it.

Does anybody know how can be done this?
manolo7
Posts: 7
Joined: 2009-06-18 10:29:45

Post by manolo7 »

Here is the solution for extracting the first line:

Code: Select all

var
s, t: string;
w: integer;

begin
s := GetField(FieldDescription);
w := Pos('<h3>Description',s);
t := copy(s, 1, w-3);
SetField(FieldLanguages, t);
end.
bad4u
Posts: 1148
Joined: 2006-12-11 22:54:46

Post by bad4u »

Another way would be using StringUtils1 and TextBefore function:

Code: Select all

uses
  StringUtils1;
var
  value: string;

begin
  value := GetField(FieldDescription);
  value := TextBefore(value, #13#10, '');
  SetField(FieldLanguages, value);
  SetField(fieldDescription, RemainingText);
end.
Using variable RemainingText it finally will delete language and country from description field.
Post Reply