i:=Pos(a,'|');
SubString1:=Copy(a,1,i-1);//SubString1='123';
SubString1:=Copy(a,1,i-1);//SubString1='123';
解决方案 »
- 请指教:怎样才能让输入密码的窗口不显示?
- 请问一个Form的按钮事件中,如何写代码显示同一个Form,当然显示的Form的记录不同(里面有AdoQuery组件)
- 请教个关于DELPHI帮助文件的问题
- 请问一个FastReport直接打印问题
- firetoucher散分帖
- 1点,又是1点
- 在VC++中可以使用WinExecute来调用外部的.EXE文件,请问在Delphi中我怎么调用
- 如何在delphi程序中调用.chm的帮助文件?
- DBTEXT显示一行的问题,急!!!!!!!!!! 在线等待!!!!!!!
- 扩展名为scm为文件是什么文件,如何打开
- delphi安装问题?
- 一个困扰小妹很久的问题
function FirstDelimiter(const Delimiters, S: string): Integer;
var
i: integer;
begin
if (Delimiters = '') or (S = '') then
begin
Result := 0;
exit;
end;
for i := 1 to Length(S) do
if IsDelimiter(Delimiters, S, i) then break;
Result := i;
end;//化分子串到一个 TStrings 中, ASEPARATOR可以不止一个,例如:'|, '
procedure SplitString(AString: string; ASEPARATOR: string; AList: TStrings);
var
p: integer;
s: string;
begin
AList.Clear;
while true do
begin
p := FirstDelimiter(ASEPARATOR, AString);
if p <= 0 then p := Length(AString) + 1;
s := Trim(Copy(AString, 1, p - 1));
if s <> '' then AList.Add(s);
AString := Trim(Copy(AString, p + 1, Length(AString)));
if AString = '' then break;
end;
end;
//如果 Delimiters 和 S 都不为空,并且在 S 中找不到 Delimiters,
//那么将一直返回 1//现更改如下
//查找分割符
function FirstDelimiter(const Delimiters, S: string): Integer;
var
i: integer;
begin
Result := 0;
if (Delimiters = '') or (S = '') then exit;
for i := 1 to Length(S) do
begin
if IsDelimiter(Delimiters, S, i) then
begin
Result := i;
break;
end;
end;
end;
function GetSubStrForward(SubStr,SourceStr:String;IncludeSubstr:Boolean):String ;
Var
Index:word ;
begin
Index:= pos(SubStr,SourceStr) ;
if IncludeSubstr = true then
SourceStr:= copy(SourceStr,1,Index+length(SubStr)-1)
else
SourceStr:= copy(SourceStr,1,Index - 1) ;
result:=SourceStr ;
end ;function GetSubStrBack(SubStr,SourceStr:String;IncludeSubstr:Boolean):String ;
Var
Index:word ;
begin
Index:= pos(SubStr,SourceStr) ;
if IncludeSubstr = true then
SourceStr:= copy(SourceStr,Index,Length(SourceStr))
else
SourceStr:= copy(SourceStr,Index+length(SubStr),Length(SourceStr)) ;
result:=SourceStr ;
end ;
例子
GetSubStrForward('|','abc|bcd',false):='abc' ;
GetSubStrForward('|','abc|bcd',true):='abc|' ;GetSubStrBack('|','abc|bcd',false):='bcd' ;
GetSubStrBack('|','abc|bcd',true):='|bcd' ;
使用他们,就可以分析你的A了!
先对字符串进行预处理,也就是把字符串中的 " 换为 ""
把字符串里的 | 换成 ","
在字符串前后加一 "
将处理后的字符串赋给 Strings.CommaText, 这样Strings里就是所要的子串注意: 源字符串中不能含有空格,否则此法无效!
mDataB: Variant): Variant; { 如果Bool为True则返回DataA, 否则返回DataB }
begin
if mBool then
Result := mDataA
else
Result := mDataB;
end; { ZsIif }function ZsGoto(mStr: string; mSetChar: TSetChar; mCount: Integer = 1;
mLeft: Boolean = True): string; { 取字串直到mSetChar在mStr中出现mCount次结束 }
var
I, J, K, L: Integer;
begin
Result := '';
K := 0;
L := Length(mStr);
for I := 1 to L do
begin
J := ZsIif(mLeft, I, Succ(L - I));
if mStr[J] in mSetChar then Inc(K);
if K >= mCount then Break;
Result :=
ZsIif(mLeft, '', mStr[J]) + Result + ZsIif(mLeft, mStr[J], '');
end;
end; { ZsGoto }function ZsTogo(mStr: string; mSetChar: TSetChar; mCount: Integer = 1;
mLeft: Boolean = True): string; { 取字串直到mSetChar在mStr中出现mCount次开始 }
var
I, J, K, L: Integer;
begin
Result := '';
K := 0;
L := Length(mStr);
for I := 1 to L do begin
J := ZsIif(mLeft, I, Succ(L - I));
if K >= mCount then Result :=
ZsIif(mLeft, '', mStr[J]) + Result + ZsIif(mLeft, mStr[J], '');
if mStr[J] in mSetChar then Inc(K);
end;
end; { ZsTogo }//ZsGoto('123|wersdf|5tyy66||4k90j|', ['|'], 1, True); //'123'
//ZsTogo('123|wersdf|5tyy66||4k90j|', ['|'], 1, True); //'wersdf|5tyy66||4k90j|'
//ZsGoto('123|wersdf|5tyy66||4k90j|', ['|'], 1, False); //''
//ZsTogo('123|wersdf|5tyy66||4k90j|', ['|'], 1, False); //'123|wersdf|5tyy66||4k90j'
//ZsGoto('123|wersdf|5tyy66||4k90j|', ['|'], 2, True); //'123|wersdf'
//ZsTogo('123|wersdf|5tyy66||4k90j|', ['|'], 2, True); //'5tyy66||4k90j|'
参数说明: ps_String 字符串
pi_Index 子串序号
ps_Sep 分隔符
返 回 值: 字符串子串,若失败则返回空串
*********************************************************************/String ls_SubString
Integer p, ips_String = Trim(ps_String)p = Pos(ps_String, ps_Sep)
If p <= 0 Then p = Len(ps_String) + 1ls_SubString = Left(ps_String, p - 1)For i = 2 To pi_Index
ps_String = Trim(Right(ps_String, Len(ps_String) - Len(ls_SubString) - 1)) p = Pos(ps_String, ps_Sep)
If p <= 0 Then p = Len(ps_String) + 1
ls_SubString = Left(ps_String, p - 1)
NextReturn ls_SubString