Find function

whether is there the equivalent function for the Visual Basic "Split" functions in Delphi?
ourAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MotazCommented:
What did Split function did in VB ?
0
MotazCommented:
Delete function.

e.g.

Text:= 'Hello there';
Delete(Text, 1, 2);
ShowMessage(Text); // 'llo there'

Motaz
0
MotazCommented:
Delete(Str, Position, Length);

Str: String you want to cut from.

Position: First position of substring you want to cut.

Length: Length of substring to be deleted
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

MotazCommented:
Sorry our, I'm wrong Split function is not like Delete, instead use TStringList like this example:

-Drop a button and a ListBox

procedure TForm1.Button1Click(Sender: TObject);
var
  List: TStringList;
begin
  List:= TStringList.Create;
  List.CommaText:= 'First,Second,Third';
  ListBox1.Items:= List;
  List.Free;

end;

Motaz
0
MotazCommented:
Items must be seperated by comma (,)

0
ourAuthor Commented:
Sorry ! Maybe I give  an example.
In VB
Split("we:are:friend",":")
Answer is
we
are
friend
0
ourAuthor Commented:
TStringList's CommaText are make up "spaces, commas or quotes",but ":"?
0
florisbCommented:
Errr.

use this function to split a string seperated by somthing.

F.e.

line := 'a,b,c,d,e'
value1 := Leesveld(line,','); //value1 = a; line = b,c,d,e
value2 := Leesveld(line,','); //value2 = b; line = c,d,e

et cetera.

Floris.


function TForm1.LeesVeld(var regel: String; Seperator : String):String;
///
begin
  Result := Copy(regel, 0, pos(Seperator, regel)-1);
  regel := Copy(regel, pos(Seperator, regel)+1, length(regel));

/// empty fields.
if Result = '' then
   Result := '0';
end;

0
kretzschmarCommented:
hi our,

(do you miss a function,
then create it byself ;-))

similar to florisb

Function SplitIt(Var StrToSplit : String; SplitStr : String) : String;
begin
  Result := copy(StrToSplit,1,pos(SplitStr,StrToSplit)-1);
  if Result = '' then
  begin
    Result := StrToSplit;
    StrToSplit := '';
  end
  else  Delete(StrToSplit,1,pos(SplitStr,StrToSplit)+Length(SplitStr)-1);
end;

//usage
procedure TForm1.Button1Click(Sender: TObject);
var S : String;
begin
  S := '1,2,3,4,5,6';
  while S <> '' do Listbox1.Items.Add(SplitIt(s,','));
  S := '1xx2xx3xx4xx5xx6';
  while S <> '' do Listbox1.Items.Add(SplitIt(s,'xx'));
end;

meikl
0
robtanner129Commented:
Define the function, please.  What does it take as parameters, what does it return as a result?
What do you want?
Is this good?

Function Split(s: string): TStringList;
0
GoodTimesCommented:
I wrote a function, similar to what you need, with a little bit more functionality: what it does is receive a string and a separator, and returns a dynamic array which has in each cell the separated text:

Type
   TParams : array of string;
....
....
....
function GetParams(var Params : TParams; S : String; Separator : Char) : integer;
var
  i, j, t : integer;
  tmpStr : String;
  Continue : Boolean;
begin
  j := 0;

  for i := 1 to Length(S) do
    if S[i] = Separator then Inc(j);
  Inc(j);

  SetLength(Params, j);

  Result := j;

  tmpStr := S;

  Continue := True;
  i := Length(tmpStr);
  for t := j-1 downto 0 do
  begin
    while Continue do
    begin
      if tmpStr[i] = Separator then
        Continue := false
      else Dec(i);
    end;
    Params[t] := Copy(tmpStr, i +1, Length(tmpStr) - i +1);
    Delete(tmpStr, i, Length(tmpStr) - i+1);
    i := Length(tmpStr);
    Continue := True;
  end;
end;

---------------------

here Params is the dynamic-array and the result of the function is its length. (from 0 to n-1).

Does this help?

Regards,
Omri
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robtanner129Commented:
Probably it would be wiser to use a dynamic array more familiar to Delphi users.  In this case, a TStringList is more appropriate, although I realize this is more of a style point.  This avoids all the headaches of casting pointers etc.  

Again, a clear definition of the function has not been given.

Is this good?

Function Split(s: string; Delimiter:Char): TStringList;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.