[Lazarus] [resolved] How to use TRegExpr class (in synregexpr.pas)
FreeMan
freeman35 at delphiturkiye.com
Fri Oct 25 15:28:44 CEST 2013
Thank you Dave,
I learned one more think too. I was write so long time ago similar
"DelChars" function, now I delete it from my library. 'cos freepascal
has it.
Delspace delete just #32. On my test I saw #0 (I don't now how and
why)so I wroteguarantee code #0 to #32 will not useing chars so delete
very small code.
strutils.pp has many string function, I been happy, thanks again Dave
25-10-2013 15:01 tarihinde, David Copeland yazdı:
> I see that the starting IP can have imbedded spaces. Trim only removes
> leading and trailing space. I believe the DelSpace function will remove
> all space.
>
> Dave.
>
> On 10/25/2013 07:31 AM, FreeMan wrote:
>> This is version is penultimate version :)
>> '127.000. 0 .01 ' result is '127.0.0.1'
>> I tested this in:
>> Kubuntu 13.10 x64
>> fpc svn update 25845
>> lazarus svn update 43320
>>
>> function IP4OK(pT: String): String;
>> var r : TRegExpr;
>> i,j: Integer;
>>
>> function My_Trim(S : String): String;
>> Const myWhiteSpace = [#0..#32];
>> var I: Integer;
>> begin
>> Result := '';
>> Try
>> I := 1;
>> while I<=Length(S)do Begin
>> if not(S[I]in MyWhiteSpace)then Result := Result + S[I];
>> Inc(I,1);
>> end;
>> Except
>> Result := '';
>> end;
>> end;
>> begin
>> try
>> Result := '';
>> r := TRegExpr.Create;
>> r.Expression := '^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$';
>> pT := My_Trim(pT);
>> if r.Exec(pT) then begin
>> for i := 1 to 4 do begin
>> J := StrToInt(r.Match[i]);
>> if J > 255 then begin
>> Result := '';
>> Break;
>> end else begin
>> if Result<>''then Result := Result + '.';
>> Result := Result + IntToStr(J);//for delete space and zero on
>> left
>> end;
>> end;
>> end;
>> finally
>> r.Free;
>> end;
>> end;
>>
>> --
>> _______________________________________________
>> Lazarus mailing list
>> Lazarus at lists.lazarus.freepascal.org
>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>>
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
More information about the Lazarus
mailing list