📄 smasshare.~pas
字号:
unit SMASShare;
interface
uses
sysUtils,Dialogs,Windows,Messages;
type
TJPSMASShare=class
public
class function compressCellPhone(cellPhone:string):string;
class function getCellPhoneType(cellPhone:string):byte;
end;
TJPSmasSPNumParser=class
private
cmSPNum,
cuSPNum:string;
function parseSPNum(rootSPNum,fullSPNum:string):string;
function compressSPNum(rootSPNum,uSPNum:string):string;
public
constructor create(cmSPNum,cuSPNum:string);
procedure parse(cellPhone,SPNum:string;var xSPID:string);
procedure compose(cellPhone:string;uSPNum:string;var SPNum:string);
end;
implementation
{ TJPSmasSPNumParser }
procedure TJPSmasSPNumParser.compose(cellPhone, uSPNum: string;
var SPNum: string);
begin
case TJPSMASShare.getCellPhoneType(cellPhone) of
1:SPNum:=compressSPNum(cuSPNum,uSPNum);
2:SPNum:=compressSPNum(cmSPNum,uSPNum);
end;
end;
function TJPSmasSPNumParser.compressSPNum(rootSPNum,
uSPNum: string): string;
var
rootLen:byte;
begin
if rootSPNum=uSPNum then
result:=uSPNum
else begin
rootLen:=length(rootSPNum);
if copy(uSPNum,1,rootLen)=rootSPNum then
result:=uSPNum
else result:=rootSPNum+uSPNum;
end;
end;
constructor TJPSmasSPNumParser.create(cmSPNum, cuSPNum: string);
begin
self.cmSPNum:=cmSPNum;
self.cuSPNum:=cuSPNum;
end;
procedure TJPSmasSPNumParser.parse(cellPhone,SPNum: string; var xSPID: string);
begin
case TJPSMASShare.getCellPhoneType(cellPhone) of
1:xSPID:=parseSPNum(cuSPNum,SPNum);
2:xSPID:=parseSPNum(cmSPNum,SPNum);
end;
end;
function TJPSmasSPNumParser.parseSPNum(rootSPNum, fullSPNum: string): string;
var
rootLen:byte;
begin
if rootSPNum=fullSPNum then
result:=''
else begin
rootLen:=length(rootSPNum);
if copy(fullSPNum,1,rootLen)=rootSPNum then
result:=copy(fullSPNum,rootLen+1,length(fullSPNum)-rootLen)
else result:=fullSPNum;
end;
end;
{ TJPSMASShare }
class function TJPSMASShare.compressCellPhone(cellPhone: string): string;
begin
cellPhone:=trim(cellPhone);
if copy(cellPhone,1,2)='86' then
cellPhone:=copy(cellPhone,3,length(cellPhone)-2);
result:=cellPhone;
end;
class function TJPSMASShare.getCellPhoneType(cellPhone: string): byte;
var
intPhone:word;
begin
intPhone:=strtoint(copy(TJPSMASShare.compressCellPhone(cellPhone),1,3));
case intPhone of
130..133:result:=1;
134..139:result:=2;
else result:=0;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -