Skip to main content

pascal with the lazarus ide doing text extraction using regular expressions


pascal with the lazarus ide extracting doing text extraction using regular expressions

download my pascal program which uses regular expressions here..
lazarusWs.zip

unzip the lazarusWs.zip file.
From Blogger Pictures

open the 'trwRegExp.lpi' file with the 'lazarus ide'
From Blogger Pictures

program trwRegExp;

uses
    ctypes, strings, regexpr, sysutils;

var
   numChars : integer;
   lineStr : string;
   linePch : PChar;
type
    stringValues = array[1..50] of real;

const
     hello = 'hello';

{----------------------------------------------------------------------}
function numElements(csvLine : PChar) : integer; stdcall;

var
   regularExpression : pchar;
   tRegExprEng : tregexprengine;
   success : boolean;
   index, len, loopCounter, stringLength, liIndex, liLength : integer;
   holdString, stringItem : string;
   holdPcharString : pchar;
   newPcharString : pchar;


begin
     loopCounter := 0;
     index := 0;
     len := 0;
     liIndex := 0;
     liLength := 0;
     regularExpression := '\-?[0-9]+(\.[0-9]+)?';
     stringLength := 0;

     tRegExprEng := GenerateRegExprEngine(regularExpression, [ref_singleline] );
     success := RegExprPos(tRegExprEng, csvLine, index, len);

     while (success and (loopCounter < 10)) do
     begin
          loopCounter := loopCounter + 1;

          stringLength := length(StrPas(csvLine));

          holdString := Copy(StrPas(csvLine), (index + len + 1), stringLength + 1 - len);

          stringItem := copy(StrPas(csvLine), index, len + 1);
          holdPcharString := StrAlloc(length(holdString) + 1);
          holdPcharString := StrPCopy(holdPcharString, holdString);

          //writeln('loop->' + IntToStr(loopCounter) + ' index->' + intToStr(index) + ' len->' + intToStr(len) + ' strItem->' + stringItem + ' str->' + holdString);

          csvLine := holdPcharString;
          success := RegExprPos(tRegExprEng, holdPcharString, index, len);
     end;

     DestroyregExprEngine(tRegExprEng);

     numElements  := loopCounter;
end;


function getElement(csvLine : PChar; elementIndex : integer) : pchar; stdcall;
var
   regularExpression : pchar;
   tRegExprEng : tregexprengine;
   success : boolean;
   index, len, loopCounter, stringLength, liIndex, liLength : integer;
   holdString, stringItem : string;
   holdPcharString : pchar;
   newPcharString : pchar;
   valDouble : cdouble;


begin
     loopCounter := 0;
     index := 0;
     len := 0;
     liIndex := 0;
     liLength := 0;
     regularExpression := '\-?[0-9]+(\.[0-9]+)?';
     stringLength := 0;

     tRegExprEng := GenerateRegExprEngine(regularExpression, [ref_singleline] );
     success := RegExprPos(tRegExprEng, csvLine, index, len);

     while (success and (loopCounter < elementIndex)) do
     begin
          loopCounter := loopCounter + 1;

          stringLength := length(StrPas(csvLine));

          holdString := Copy(StrPas(csvLine), (index + len + 1), stringLength + 1 - len);
          holdPcharString := StrAlloc(length(holdString) + 1);
          holdPcharString := StrPCopy(holdPcharString, holdString);

          stringItem := copy(StrPas(csvLine), index, len + 1);

          csvLine := holdPcharString;
          success := RegExprPos(tRegExprEng, holdPcharString, index, len);
     end;

     DestroyregExprEngine(tRegExprEng);

     holdPcharString := StrAlloc(length(stringItem) + 1);
     holdPcharString := StrPCopy(holdPcharString, stringItem);

     getElement  := holdPcharString;
end;


begin
     lineStr := '   -1111111110, 220.223, -3330.445, 44440, 555550, 6666660, 77777770';

     linePch := StrAlloc(length(lineStr) + 1);
     linePch := StrPCopy(linePch, lineStr);

     writeln('numElements >' + IntToStr(numElements(linePch)));

     for numChars := 1 to numElements(linePch) do
     begin
          writeln('getElement..' + getElement(linePch, numChars));
     end;
end.


after clicking the 'green' arrow like button (compile the program) then run the compiled pascal
program.

From Blogger Pictures

Comments

Popular posts from this blog

clonezilla - creating a wifi ad-hoc hotspot and running a ssh server

Here are some notes on connecting to a wifi-hotspot from a running clonezilla
live-cd.

[ target machine to save a backup hard-disk clone/image ]
[ target machine is also running a wifi hotspot and an ssh server ]
Ubuntu 11.04 - Natty Narwhal

terry@terry-HP:~$ uname -a
Linux terry-HP 2.6.38-10-generic #46-Ubuntu SMP Tue Jun 28 15:07:17 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
terry@terry-HP:~$

[ Creating an 'ad-hoc' wifi spot ]
Click the 'up down arrow' icon ( or what have you )


[ choose menu item to create a wifi ad-hoc hotspot ]

[ create the ad-hoc wifi hotspot ]

[ the eth1 connection is the created ad-hoc network with an essid of 'terry' ]

[ the ad-hoc wifi hotspot is now visible on the 'host' computer and other computer as well now ]

[ enter the following on the machine being cloned with clonezilla
[ at the appropriate place in the clonezilla backup image step ]
terry@terry-HP:~$ ip link set wlan0 down
terry@terry-HP:~$ iwconfig wlan0 mode ad-hoc
terry@…

Translators, maps, conduits, and containers

Interpreters
The Amiga had a hardware emulator which transformed instruction to instruction to a dedicated x86 hardware interpreter in the Amiga could run Microsoft DOS spreadsheet programs in the Amiga OS.

MS-DOS on Amiga via Sidecar or Bridgeboard[edit]
MS-DOS compatibility was a major issue during the early years of the Amiga's lifespan in order to promote the machine as a serious business machine. In order to run the MS-DOS operating system, Commodore released the Sidecar for the Amiga 1000, basically a 8088 board in a closed case that connected to the side of the Amiga. Clever programming (a library named Janus, after the two-faced Roman god of doorways) made it possible to run PC software in an Amiga window without use of emulation. At the introduction of the Sidecar the crowd was stunned to see the MS-DOS version of Microsoft Flight Simulator running at full speed in an Amiga window on the Workbench.

Later the Sidecar was implemented on an expansion card named "Bridgebo…

Use Gwenview to upload images to picasaweb.google.com

Use Gwenview to upload images to https://picasaweb.google.com/

install the following KDE4 plugins:

terry@narwhal:~/download$ sudo apt-get install kipi-plugins
From Linux Clicks...
the Gwenview application...

From Linux Clicks...