IP 取值问题,帮忙看下哦 IP:=‘192.168.1.120’IP:=‘192.168.001.120’上面2种情况 我怎么才能取到后两位呢,考虑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 取的结果是20?copy(ip,length(ip)-1,length(ip));//手头没有DELPHI,你可以试试 或copy(ip,length(ip)-1,2);//手头没有DELPHI,自己调一下。 copy(para1,para2,para3);//三个参数的意思分别是:原字符串,开始截取的位置,截取位数。所以只需相应调整第二个和第三个参数的数值即可。 {用TstringList吧}const IP='192.168.001.120';var slist:Tstringlist;begin slist:=Tstringlist.Create; try slist.Delimiter='.'; slist.DelimitedText:=IP; showmessage(slist.Strings[0]); {192} showmessage(slist.Strings[1]); {168} showmessage(slist.Strings[2]); {001} showmessage(slist.Strings[3]); {120} finally slist.Free; end;end; 我自己想的办法是这样的大家看下 有更好的办法没前面的那个如果IP 为192.168.1.1 取后2位的话 结果为 .1 下面是我自己写的 如果最后只有1位的时候补0 m := pos('.', ip); equip := copy(ip, m + 1, length(ip)); n := pos('.', equip); equip := copy(equip, n + 1, length(equip)); p := pos('.', equip); equip := copy(equip, p + 1, length(equip)); equip := copy(equip, length(equip) - 1, length(equip)); if length(equip) = 1 then equip := '0' + equip; 就用这个 if length(slist.Strings[3])=1 thenslist.Strings[3]:='0'+slist.Strings[3]; 用delphi实现甘特图 招聘Delphi程序员 int -> str 关于TShell的问题,来者有分 菜鸟问题 各位帮帮小妹? 如何在mousedown里面记录起始点 何谓 系统接口定义?? 一次性新增问题 哪位高手帮忙下个函数。。。 如何获得鼠标在窗体外移动和单击的消息? delphi调用Oracle存储过程 动态创建1000个label,如何释放内存
copy(ip,length(ip)-1,length(ip));//手头没有DELPHI,你可以试试
var
slist:Tstringlist;
begin
slist:=Tstringlist.Create;
try
slist.Delimiter='.';
slist.DelimitedText:=IP;
showmessage(slist.Strings[0]); {192}
showmessage(slist.Strings[1]); {168}
showmessage(slist.Strings[2]); {001}
showmessage(slist.Strings[3]); {120}
finally
slist.Free;
end;
end;
equip := copy(ip, m + 1, length(ip));
n := pos('.', equip);
equip := copy(equip, n + 1, length(equip));
p := pos('.', equip);
equip := copy(equip, p + 1, length(equip));
equip := copy(equip, length(equip) - 1, length(equip));
if length(equip) = 1 then
equip := '0' + equip;
就用这个
if length(slist.Strings[3])=1 then
slist.Strings[3]:='0'+slist.Strings[3];