Viotto-Security.net - Delphi source codes


Split() function

This function emulates Visual Basic Split function. It is mainly used to split up different settings contained in a single string, into an array.

I based this code off Steve10120 Split function (thanks!) but I made various improvements:

  • Steve's function can't get data after last delimiter. VB function and mine can.
  • Steve's function performs redundant loops which, after last encountered delimiter, add empty strings to result array. This increases length of result array with useless data and can slow down execution when data is long. Plus it is more difficult to get array length because of empty elements which get added. These problems have been fixed.
  • Steve's function needed Windows under uses clause, mine doesn't need any uses.
For example on how to use, you can download example project below, which includes also original Steve's function for comparison.
Enjoy and keep credits! ;)



type TStringArray = array of string;


function
SplitStr(sInput:string; Delimiter:string):TStringArray;

 {By Viotto - Infos on http://viotto-security.net
 Based off Steve10120's Split function}
 var
  DelimPos:     Cardinal;
  LastDelimPos: Cardinal;
  StartIndex:   Cardinal;
  ElemCount:    Cardinal;
  sTemp:        string;
begin
  StartIndex := 1;
  ElemCount := 0;
  repeat
    sTemp := Copy(sInput, StartIndex, Length(sInput));
    DelimPos := Pos(Delimiter, sTemp);
    if DelimPos > 0 then
         LastDelimPos := DelimPos - 1
    else LastDelimPos := Length(sTemp);

    sTemp := Copy(sInput, StartIndex, LastDelimPos);
    SetLength(Result, Length(Result) + 1);
    Result[ElemCount] := sTemp;
    StartIndex := StartIndex + Length(sTemp) + Length(Delimiter);
    ElemCount := ElemCount + 1;
  until DelimPos = 0;

end;


Split String example (Delphi).rar Split String example (Delphi).rar
Size : 0.857 Kb
Type : rar

_______________________________________________________________________________________________

Check number of occurrencies of one substring within a string

I needed a string function which indicates how many times a substring (or character) is contained in a string. It didn't exist already in delphi functions, so I coded one myself:

Usage example:

SubstringCount('Hell', 'Hello world!'); // returns 1

Code:

uses StrUtils;

function SubstringCount (Substring : string; Str : string): Integer;
var Offset : Integer;
begin
 Result := 0;
  while Pos(Substring, Str) <> 0 do
  begin
  Result := Result + 1;
  Offset := Pos(Substring, Str);
  Str := RightStr(Str, Length(Str) - Offset);
  end;
end;

_______________________________________________________________________________________________

Extract file extension from URL / file directory / file name

It extracts the file extension no matter how much is long, so it works also with extensions that are shorter or longer than the usual 3 characters.


function GetFileExtension( sAddress: string): string;
var DotPosition : Integer;
begin
DotPosition := LastDelimiter('.', sAddress);
Result := RightStr(sAddress, Length(sAddress)-DotPosition);
end;

________________________________________________________________________________________________________________ 

Falcon Downloader


Compact downloader programmed in:

Delphi 2010  (builder)

Delphi 7 SE   (stub 1)

C++                 (stub 2)


Saves / loads setting using resources with my own method and it is crypter-compatible.


Falcon Downloader - Source.rar Falcon Downloader - Source.rar
Size : 0.567 Kb
Type : rar