User talk:Jvnnior

From MediaWiki.org
Jump to: navigation, search

Delphi Split / Tokenizer functions unit SplitFns; interface uses Classes;

function GetNextToken (Const S: string; Separator: char; var StartPos: integer): String;

{Returns the next token (substring) from string S, starting at index StartPos and ending 1 character before the next occurrence of Separator (or at the end of S, whichever comes first).} {StartPos returns the starting position for the next token, 1 more than the position in S of the end of this token}

procedure Split

 (const S: String;
 Separator: Char;
 MyStringList: TStringList) ;

{Splits a string containing designated separators into tokens and adds them to MyStringList NOTE: MyStringList must be Created before being passed to this procedure and Freed after use}

function AddToken (const aToken, S: String ; Separator: Char; StringLimit: integer):String;

{Used to join 2 strings with a separator character between them and can be used in a Join function} {The StringLimit parameter prevents the length of the Result String from exceeding a preset maximum}

implementation Uses Sysutils;






function GetNextToken (Const S: string; Separator: char; var StartPos: integer): String; var Index: integer; begin

 Result := ;

{Step over repeated separators}

While (S [StartPos] = Separator) and (StartPos <= length (S)) do StartPos: = StartPos + 1;

if StartPos > length (S) then Exit;

{Set Index to StartPos}

Index: = StartPos;

{Find the next Separator}

While (S [Index] <> Separator) and (Index <= length (S))do

  Index := Index + 1;

{Copy the token to the Result}

 Result := Copy(S, StartPos, Index - StartPos) ;

{SetStartPos to next Character after the Separator}

 StartPos := Index + 1;

end;

procedure Split

 (const S: String;
 Separator: Char;
 MyStringList: TStringList) ;

var Start: integer; begin

 Start := 1;
 While Start <= Length(S) do
   MyStringList.Add
     (GetNextToken(S, Separator, Start)) ;

end;

function AddToken (const aToken, S: String; Separator: Char; StringLimit: integer): String; begin

 if Length(aToken) + Length(S) < StringLimit then
   begin
     {Add a separator unless the
      Result string is empty}
     if S =  then
       Result := 
     else Result := S + Separator;
     {Add the token}
     Result := Result + aToken;
   end
 else
 {if the StringLimit would be exceeded, raise an exception}
   Raise Exception.Create('Cannot add token') ;

end; end. Left, Mid, Right String . LeftStr() takes a certain portion of the left side of a string. . MidStr() takes a specified number of characters from a string. . RightStr() takes a certain portion of the right side of a string.

Let's say we have a string Dstr := 'Delphi is the BEST', then LeftStr(Dstr, 5) := 'Delph' MidStr(Dstr, 6, 7) := 'i is th' RightStr(Dstr, 6) := 'e BEST' 16:43, 10 July 2006 (UTC)16:43, 10 July 2006 (UTC)16:43, 10 July 2006 (UTC)16:43, 10 July 2006 (UTC)16:43, 10 July 2006 (UTC) function RightStr

  (Const Str: String; Size: Word): String;

begin

if Size > Length(Str) then Size := Length(Str) ;
RightStr := Copy(Str, Length(Str)-Size+1, Size)

end;

function MidStr

  (Const Str: String; From, Size: Word): String;

begin

MidStr := Copy(Str, From, Size)

end;

function LeftStr

  (Const Str: String; Size: Word): String;

begin

LeftStr := Copy(Str, 1, Size)

end; 16:43, 10 July 2006 (UTC)16:43, 10 July 2006 (UTC)16:43, 10 July 2006 (UTC)16:43, 10 July 2006 (UTC)16:43, 10 July 2006 (UTC) p.s. Or, if you have Delphi 6+, you an use the LeftStr, RightStr or the Copy RTL functions. Delphi tips navigator:

Retirado de "http://www.mediawiki.org/wiki/Project:Ajuda"

[edit] Relevance with MediaWiki

Hi Jvnnior, MediaWiki.org is a site which has as goal the development of the MediaWiki software. I'm not sure your contributions like Project:Ajuda and Image:Jvnnior.pdf have really a link with MediaWiki (but perhaps, I have not see in details ; if it's the case, sorry). Else Image:Luis Royo - Caress.jpg has really no relevance with MediaWiki, I have requested his deletion. ~ Seb35 11:31, 11 July 2006 (UTC)

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox