Page 1 of 1

Extract first line from a description field

Posted: 2009-06-19 13:44:13
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?

Posted: 2009-06-19 17:17:59
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.

Posted: 2009-06-19 18:55:21
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.