请问DELPHI有类似VB的mid之类的函数吗?(100分)

Z

zj2000

Unregistered / Unconfirmed
GUEST, unregistred user!
请问DELPHI有类似VB的mid,left,right
之类的函数吗?
 
J

jiangtao

Unregistered / Unconfirmed
GUEST, unregistred user!
http://www.netease.com/~cyhan/vcl_files/BASICS.ZIP
这里面有用Delphi 实现的50多个 VB的函数
{+-------------------------------------------------------+}
{: Function : LEFT :}
{+-------------------------------------------------------+}
{: Syntax : LEFT ( <expC> , <expN> ) :}
{: :}
{: where : <expC> = character string :}
{: <expN> = number of characters to return :}
{: Integer value :}
{: :}
{: Action : Returns a specified number of characters :}
{: in the character string <expC>, starting :}
{: from the leftmost character. :}
{: :}
{: Result Type : String :}
{+-------------------------------------------------------+}
Function Left;
begin
Left := Copy(inString,1,numChars)
end;

{+-------------------------------------------------------+}
{: Function : RIGHT :}
{+-------------------------------------------------------+}
{: Syntax : RIGHT ( <expC> , <expN> ) :}
{: :}
{: where : <expC> = character string :}
{: <expN> = number of characters to return :}
{: Integer value :}
{: :}
{: Action : Returns the rightmost <expN> portion of a :}
{: character string <expC> :}
{: :}
{: Result Type : String :}
{+-------------------------------------------------------+}
Function Right;
Var
index : Byte;
begin
If numChars >= Length(inString) then
Right := inString
else
begin
index := Length(inString) - numChars+1;
Right := Copy(inString,index,numChars)
End
end;
 
J

jiangtao

Unregistered / Unconfirmed
GUEST, unregistred user!
忘了Mid,其实主要就是用Copy函数,
function Copy(S: string;
Index, Count: Integer): string;
Description
The Copy function returns a substring of a string.

function Mid(Const Str: String;
Size: Word): String;
var len: Byte absolute Str;
begin
if Size > len then
Size := len;
Mid := Copy(Str,((len - Size) div 2)+1,Size)
end {Mid};
 
A

Another_eYes

Unregistered / Unconfirmed
GUEST, unregistred user!
function Mid(str: string;
len: integer):string;
begin
if length(str)>=len then
begin
result:=str;
exit;
end;
SetString(result,nil,len);
move(result[(len-length(str)) div 2 + 1], str[1], length(str));
end;

不限str长度.
 
A

Another_eYes

Unregistered / Unconfirmed
GUEST, unregistred user!
抱歉,
move前漏了一句
fillchar(result[1],len, #32);
 
Z

zj2000

Unregistered / Unconfirmed
GUEST, unregistred user!
Thank You!
 
顶部