function GetString(SourceString:String;CutType,Count:Integer):String; var len:Integer; begin len := Length(SourceString); case CutType of 0://从左边 begin Result := Copy(SourceString,1,Count); end; 1:// begin if Count < len then begin Result := Copy(SourceString,len-Count+1,Count); end else begin Result := SourceString; end; end; end; end;procedure TForm1.Button1Click(Sender: TObject); begin //从左边 Self.Caption := GetString(Edit1.Text,0,5); end;procedure TForm1.Button2Click(Sender: TObject); begin //从右边 Self.Caption := GetString(Edit1.Text,1,5); end;
4:表示从第四个开始
5:表示取5个
begin
Result := Copy(AText, 1, ACount);
end;function RightStr(const AText: string; const ACount: Integer): string;
begin
Result := Copy(AText, Length(AText) + 1 - ACount, ACount);
end;
midstr('aaaaaaa',4,2);//第4个开始的2位。
rightstr('sssss',2);//右边2位.
var
len:Integer;
begin
len := Length(SourceString);
case CutType of
0://从左边
begin
Result := Copy(SourceString,1,Count);
end;
1://
begin
if Count < len then
begin
Result := Copy(SourceString,len-Count+1,Count);
end
else
begin
Result := SourceString;
end;
end;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
//从左边
Self.Caption := GetString(Edit1.Text,0,5);
end;procedure TForm1.Button2Click(Sender: TObject);
begin
//从右边
Self.Caption := GetString(Edit1.Text,1,5);
end;
POS函数定位
leftstr()
midstr()
rightstr()