大下!DELPHI中取子串的函数叫(象VB的MID())? 及判断数据类型的函数名叫?

wzs 2000-09-04 08:36:00
...全文
490 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzs 2000-09-04
  • 打赏
  • 举报
回复
天啊让我跳楼吧你们都不明白我的意思我的意是:
1。如果有一个任意长的字符串变量我想取他的一个子串就象VB有一个函数MID(STR,N1,N2)它可从STR中的取第N1个开始的N2个字符。
2。如果在EDIT.TEXT输入的字符串是日期型的格式那没什么,如果不是呢?那应怎么做判断还有我只想在EDIT中输入的只是数字而不是字母那要如何判断?所以我想知道有没有判断数据类型的函数。
fyje 2000-09-04
  • 打赏
  • 举报
回复
我也想判断,难啊
czq 2000-09-04
  • 打赏
  • 举报
回复
使用 copy 函数 判断数据类型 呵呵 可不是 vb 那样没有规矩 一般都是事先知道
可以自己写一些函数 用罗 又不难
蝈蝈俊 2000-09-04
  • 打赏
  • 举报
回复
判断数据类型????

object pascal 是种严格定义的程序语言,变量必须提前定义,你为何要判断????
蝈蝈俊 2000-09-04
  • 打赏
  • 举报
回复
错了,是 copy 函数。呵呵呵,不好意思

Returns a substring of a string or a segment of a dynamic array.

Unit

System

Category

string handling routines

function Copy(S; Index, Count: Integer): string;
function Copy(S; Index, Count: Integer): array;

Description

S is an expression of a string or dynamic-array type. Index and Count are integer-type expressions. Copy returns a substring or sub array containing Count characters or elements starting at S[Index].

If Index is larger than the length of S, Copy returns an empty string or array.

If Count specifies more characters or array elements than are available, only the characters or elements from S[Index] to the end of S are returned.

Note: When S is a dynamic array, Copy can only be used as a parameter in a call to a procedure or function that expects an array parameter. That is, it acts like the Slice function when working with dynamic arrays.
蝈蝈俊 2000-09-04
  • 打赏
  • 举报
回复
你是不是要这个
strpos() 在一个字符串中收索某个子串,并返回一个指针,指向第一次出现的地方.
smallBridge 2000-09-04
  • 打赏
  • 举报
回复
1、用COPY函数,方法和VB中的MID函数是一样的

2、用function VarType(const v:Variant):integer 函数:

------------------------------------------------------------------------------
Description

VarType returns the type code of the given Variant. The resulting value is constructed from the following constants declared in the System unit.

const

varEmpty = $0000;
varNull = $0001;
varSmallint = $0002;
varInteger = $0003;
varSingle = $0004;
varDouble = $0005;
varCurrency = $0006;
varDate = $0007;
varOleStr = $0008;
varDispatch = $0009;
varError = $000A;
varBoolean = $000B;
varVariant = $000C;
varUnknown = $000D;
varByte = $0011;

varStrArg = $0048;

varString = $0100;
varAny = $0101;
varTypeMask = $0FFF;
varArray = $2000;

varByRef = $4000;

The lower twelve bits of a Variant type code (the bits defined by the varTypeMask bit mask) define the type of the Variant. The varArray bit is set if the Variant is an array of the given type. The varByRef bit is set if the Variant is a reference to a value of the given type as opposed to an actual value.

The following table describes the meaning of each of the Variant type codes.

VarType Contents of Variant

varEmpty The Variant is Unassigned.
varNull The Variant is Null.
varSmallint 16-bit signed integer (type Smallint).
varInteger 32-bit signed integer (type Integer).
varSingle Single-precision floating-point value (type Single).
varDouble Double-precision floating-point value (type Double).
varCurrency Currency floating-point value (type Currency).
varDate Date and time value (type TDateTime).
varOleStr Reference to a dynamically allocated UNICODE string.

varDispatch Reference to an Automation object (an IDispatch interface pointer).
varError Operating system error code.
varBoolean 16-bit boolean (type WordBool).
varVariant A Variant.
varUnknown Reference to an unknown OLE object (an IUnknown interface pointer).
varByte A Byte
varStrArg COM-compatible string.
varString Reference to a dynamically allocated string. (not COM compatible)
varAny A CORBA Any value.

The value returned by VarType corresponds to the VType field of a TVarData record.

The type of a Variant can be changed using VarAsType or VarCast.
smallBridge 2000-09-04
  • 打赏
  • 举报
回复
用function VarType(const v:Variant):integer 函数:

------------------------------------------------------------------------------
Description

VarType returns the type code of the given Variant. The resulting value is constructed from the following constants declared in the System unit.

const

varEmpty = $0000;
varNull = $0001;
varSmallint = $0002;
varInteger = $0003;
varSingle = $0004;
varDouble = $0005;
varCurrency = $0006;
varDate = $0007;
varOleStr = $0008;
varDispatch = $0009;
varError = $000A;
varBoolean = $000B;
varVariant = $000C;
varUnknown = $000D;
varByte = $0011;

varStrArg = $0048;

varString = $0100;
varAny = $0101;
varTypeMask = $0FFF;
varArray = $2000;

varByRef = $4000;

The lower twelve bits of a Variant type code (the bits defined by the varTypeMask bit mask) define the type of the Variant. The varArray bit is set if the Variant is an array of the given type. The varByRef bit is set if the Variant is a reference to a value of the given type as opposed to an actual value.

The following table describes the meaning of each of the Variant type codes.

VarType Contents of Variant

varEmpty The Variant is Unassigned.
varNull The Variant is Null.
varSmallint 16-bit signed integer (type Smallint).
varInteger 32-bit signed integer (type Integer).
varSingle Single-precision floating-point value (type Single).
varDouble Double-precision floating-point value (type Double).
varCurrency Currency floating-point value (type Currency).
varDate Date and time value (type TDateTime).
varOleStr Reference to a dynamically allocated UNICODE string.

varDispatch Reference to an Automation object (an IDispatch interface pointer).
varError Operating system error code.
varBoolean 16-bit boolean (type WordBool).
varVariant A Variant.
varUnknown Reference to an unknown OLE object (an IUnknown interface pointer).
varByte A Byte
varStrArg COM-compatible string.
varString Reference to a dynamically allocated string. (not COM compatible)
varAny A CORBA Any value.

The value returned by VarType corresponds to the VType field of a TVarData record.

The type of a Variant can be changed using VarAsType or VarCast.
LaoZheng 2000-09-04
  • 打赏
  • 举报
回复
flyby说的对。
日期输入你可以用一个日期输入控件。
xfchai 2000-09-04
  • 打赏
  • 举报
回复
Pos(substr,str)
dragongong 2000-09-04
  • 打赏
  • 举报
回复
1.根本就不应该存在这样的问题,如果需要限制输入格式你应该使用MaskEdit.
设置mask:= '!99/99/00;1;_';如果需要设置长日期格式则设置mask:= '!99/99/00 90:00:00;1;_'.
2.如果需要按分隔符获取字串请使用这个函数
Function tuGetBlock(SourceString:String; Spearate:String; iPos:integer):String;
var
tmpStr:String;
i:integer;
begin
TmpStr:= SourceString;
for i:=0 to iPos-1 do
begin
if pos(Spearate,TmpStr)<>0 then
begin
Result:= Copy(TmpStr,1,pos(Spearate,tmpStr)-length(Spearate));
TmpStr:= Copy(TmpStr,pos(Spearate,tmpStr)+length(Spearate),length(TmpStr)-pos(Spearate, tmpStr));
end else begin
if i = iPos-1 then Result:= TmpStr else Result:= '';
break;
end;
end;
end;
例如: iMonth = StrToInt(tuGetblock('2000/09/04','/',2));
这个函数似乎可以再优化一下,希望那位大虾指点.
flyby 2000-09-04
  • 打赏
  • 举报
回复
1、str2:=copy(str1,n1,n2);
2、edit.text一定是字符串类型的,但可以将他转化为其他类型:
StrToDate 函数 将字符串转换为日期格式
StrToDateTime 函数 将字符串转换为日期/时间格式
StrToFloat 函数 将给定的字符串转换为浮点数
StrToInt 函数 将字符串转换为整型
StrToIntDef 函数 将字符串转换为整型或默认值
StrToTime

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧