字符串简单问题

omarchen 2006-05-25 10:21:59
一个不定长度的字符串,如何得到从第3个字符到倒数第3个字符中的那传字符
如asdfghjkl要求得到dfghj
...全文
301 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞哥 2006-05-31
  • 打赏
  • 举报
回复
而且可以配合pos来用

pos 查找子串首次出现的位置
function Pos(Substr: string; S: string): Integer;

Description

In Delphi, Pos searches for a substring, Substr, in a string, S. Substr and S are string-type expressions.

Pos searches for Substr within S and returns an integer value that is the index of the first character of Substr within S. Pos is case-sensitive. If Substr is not found, Pos returns zero.

The PosEx function is similar to Pos, but provides additional features and can be used in C++ code.
飞哥 2006-05-31
  • 打赏
  • 举报
回复
总结:

ls同仁一致认为用copy
没错
就是copy
September_1984 2006-05-31
  • 打赏
  • 举报
回复
s:= 'asdfghikl'
copy(s,3,length(s)-3);
diablobaal 2006-05-25
  • 打赏
  • 举报
回复
楼上正解
copy函数说明
copy(a,b,c)
将字符串a从第b位开始取,取c个位的子串
andyzhou1101 2006-05-25
  • 打赏
  • 举报
回复
错了
想说的是
sSou := 'asdfghjkl';
sTar := Copy(sSou, 3, Length(sSou) - 4));
多了个')'
andyzhou1101 2006-05-25
  • 打赏
  • 举报
回复
Copy('asdfghjkl', 3, Length(sSou) - 4);
jadeluo 2006-05-25
  • 打赏
  • 举报
回复
sSou := 'asdfghjkl';
sTar := Copy(sSou, 3, Length(sSou) - 4));
aniude 2006-05-25
  • 打赏
  • 举报
回复
Var r2:TRegExpr;
Var s:String;
begin
r2:=TRegExpr.Create;
s:='asdfghjkl';
r2.Expression:='.{2}(.+).{2}';
if r2.Exec(s) Then
ShowMessage(r2.Match[1]);
end;
aniude 2006-05-25
  • 打赏
  • 举报
回复
感觉DELPHL在字符串方面不爽,除非用正则
aniude 2006-05-25
  • 打赏
  • 举报
回复
var str_Tmp:String;
begin
str_Tmp:='asdfghjkl';
ShowMessage(Copy(str_Tmp,3,Length(str_Tmp)-4));
end;
johnzcq 2006-05-25
  • 打赏
  • 举报
回复
var str : string ;

begin
str := copy ( 'asdfghjkl' , 3 , ( length( 'asdfghjkl' ) - 4 ) ) ;
end ;


说明:
字符串函数COPY

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

其中:
S : 指明要进行操作的字符串,
INDEX : 指明截取起点,
COUNT : 指明截取长度。

16,747

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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