Sumber Kode

Simple Split Function - Reading settings from executables.

  • delphibasics
  • Nov 19' 14
  • Delphi
  • 31
  • 292
  • United States
After reading our previous tutorials, many of you will be using resources to store the settings for your applications.
To avoid writing and reading settings separately, you could write your settings:
 
Good, Morning and World
as
"Good||Morning||World||"  [The delimiter is "||" in this case]
 
This split function parses your settings after reading from resources into a string array for use in your application.

Coder: steve10120

Function
TStringArray = array of string;

function Split(Expression:string; Delimiter:string):TStringArray;
var
  Res:        TStringArray;
  ResCount:   DWORD;
  dLength:    DWORD;
  StartIndex: DWORD;
  sTemp:      string;
begin
  dLength := Length(Expression);
  StartIndex := 1;
  ResCount := 0;
  repeat
    sTemp := Copy(Expression, StartIndex, Pos(Delimiter, Copy(Expression, StartIndex, Length(Expression))) - 1);
    SetLength(Res, Length(Res) + 1);
    SetLength(Res[ResCount], Length(sTemp));
    Res[ResCount] := sTemp;
    StartIndex := StartIndex + Length(sTemp) + Length(Delimiter);
    ResCount := ResCount + 1;
  until StartIndex > dLength;
  Result := Res;
end;

Usage:
var
  Strings:  TStringArray;

begin
  Strings := Split('Good||Morning||World||', '||');
  MessageBox(0, PChar(Strings[2]), nil, 0);

end.
Powered by
Pasar Kode Partner

Share

  • Tags :
comments powered by Disqus

Kode Terkait

PrintWindow Example - Delphi Source Code

MiniReg - LightWeight TRegistry Replacement

Delete Self - Procedure to close and delete the current application

uFMOD Example - Play .xm files from disk, memory or resource.

Pngimage by Aphex - Create, convert to and edit .png images in delphi.

Crafting a PE File with Delphi - Creating a pe file from scratch.

Change resource strings at runtime.

Alternative Sleep Methods

Create a form with Windows API.

Drag and Drop



Kategori