Separation string function split-Delphi programming in Delphi

Source: Internet
Author: User

Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls;

Type userarray = array of string;

Type
Tform1 = Class (tform)
Edit1: tedit;
Button1: tbutton;
Procedure button1click (Sender: tobject );
Private
Function split (S: string; dot: Char): userarray;
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;

Implementation

Uses strutils;

{$ R *. DFM}

Function tform1.split (S: string; dot: Char): userarray;
VaR
STR: userarray;
I, J: integer;
Begin
I: = 1;
J: = 0;
Setlength (STR, 255 );

While pos (dot, s)> 0 do
Begin
STR [J]: = copy (S, I, pos (dot, S)-I );
I: = pos (dot, S) 1;
S [I-1]: = CHR (ord (DOT) 1 );
J: = J 1;
End;
STR [J]: = copy (S, I, strlen (pchar (s)-I 1 );
Result: = STR;
End;

Procedure tform1.button1click (Sender: tobject );
VaR
UR: userarray;
I: integer;
Begin
UR: = Split (edit1.text ,';');
For I: = 0 to 255 do
Begin
If length (UR [I]) = 0 Then exit;
Showmessage (UR [I]);
End;

End;

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.