如何判断一个字符串在另一个字符串的最后一个位置

hanlen 2006-05-20 09:53:25
如:
'_'在'a_b_c'中的最后一个位置是4。
...全文
174 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
aniude 2006-05-20
  • 打赏
  • 举报
回复
var Str:String;
j:integer;
For j:=Length(Str) DownTo 1 Do Begin
If(Str[j]='_') Then Begin
ShowMessage(IntToStr(j));
Exit;
End;
End;
kelei0017 2006-05-20
  • 打赏
  • 举报
回复
const
str1 = 'a_b_c';
var
temp: String;
no: integer;
begin
temp := 'a_b_c_';
no := Pos(str1, temp);
if no = 0 then
begin
showmessage('a_b_c都没有,不用找了');
exit;
end;
temp := Copy(temp, no + Length(str1), Legth(temp));
if Pos('_', temp) <> 0 then
showmessage('在后面')
else
showmessage('不在后面');
end;

没编译过,先把'a_b_c'后面串找出来,再找'_'
johnzcq 2006-05-20
  • 打赏
  • 举报
回复
break ;
改 Exit;
johnzcq 2006-05-20
  • 打赏
  • 举报
回复
// result := -1 ;
johnzcq 2006-05-20
  • 打赏
  • 举报
回复
const str = 'a_b_c' ;
var i , result : integer ;

begin

result := -1 ;

for i := ( length( str ) - 1 ) downto 0 do
if ( str[i] = '_' ) then
begin
result := i + 1 ;
showmessage( inttostr(result) ) ;
break ;
end ;

showmessage( 'str 中不包含 _');

end ;

16,749

社区成员

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

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