在Delphi中,字符串查找 函数
Delphi提供的字符串函数里有一个Pos函数,它的定义是:
function Pos(Substr: string; S: string): Integer;
它的作用是在字符串S中查找字符串Substr,返回值是Substr在S中第一次出现的位置,如果没有找到,返回值为0。
使用pos函数来查找字符第一次出现的位置
var
str1:string;
i,j:integer;
begin
str1:='dsf4654f6<ds>ad' ;
j:=pos('<',str1);//在字符串str1中查找"<"
if j<>0 then //得到的j是字符串中出现的位置,是整型
showmessage('<'+'在第'+inttostr(j)+'个位置'); //第十个位置
end;
===============================================
首部 function StrPos(const Str1, Str2: PChar): PChar; $[SysUtils.pas
功能 返回指针字符串Str2在Str1中第一个出现的地址
说明 没有找到则返回空指针;StrPos('12345', '3') = '345'
参考 <NULL>
例子 Edit3.Text := StrPos(PChar(Edit1.Text), PChar(Edit2.Text));
===================================================
StrScan : 返回一个字符在一个 PChar 串中第一次出现的位置指针;
StrRScan : 返回一个字符在一个 PChar 串中最后一次出现的位置指针;
StrPos : 返回一个 PChar 串在另一个 PChar 串中第一次出现的位置指针.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//StrScan、StrRScan:
procedure TForm1.Button1Click(Sender: TObject);
var
p: PChar;
str: string;
begin
str := 'ABCBBBCBA';
p := StrScan(PChar(str), 'B');
ShowMessage(p); {BCBBBCBA}
p := StrRScan(PChar(str), 'B');
ShowMessage(p); {BA}
end;
//StrPos:
procedure TForm1.Button2Click(Sender: TObject);
var
p: PChar;
str: string;
begin
str := '123456789';
p := StrPos(PChar(str), '456');
ShowMessage(p); {456789}
end;
end.
相关文档:
技术交流,DH讲解. 之前照着天书夜读,用Delphi来弄了下循环体,现在就来弄一下条件判断吧.
首先肯定是我们经常看见的IF语句咯. Var
I: Integer;
Begin
I:= 99;
If (I> 0)And (I< 0) Then
Writeln('I>0')
Else
If (I> 10)And (I< 100) Then
Writeln('I>10 and I100');
End.
反汇编出来会是 ......
tableDB.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ ExtractFilePath(dir) +';Extended Properties=dBase 5.0;Persist Security Info=False;';
tableDB.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(dir)+';Extended Pro ......
方法1:可写为函数,再调用
Application.CreateForm(TForm1, Form1);
Form1.ShowModal;
Form1.Free;
方法2:
Form1:= TForm1.Create(Application);
try
Form1.ShowModal;
finally
  ......
TThread是一个抽象类,用于在delphi中创建线程。
创建一个TThread的子类对象即相当于创建一个线程。
当一个应用程序运行时,应用程序就被载入内存准备执行。此时,它成为包含一个或多个线程的进程。线程执行应用程序的部分内容,并由操作系统分配CPU时间。同一进程的所有线程共享同一地址空间,可以访问进程的全局变量 ......