delphi 处理字符串
从下面的html字符串中提取ip地址和地址,</table><divid="op_ipmid_res1"class="op_ipmid_res"><span>您查询的IP...
从下面的html字符串中提取 ip地址和地址,
</table>
<div id="op_ipmid_res1" class="op_ipmid_res"><span>您查询的IP:<b>202.108.22.5</b></span><span>来自:<b>北京市</b></span><span style="margin:20px;font-size:13px;color:#656565">IP数据提供:<a href="http://www.ip138.com/" target="_blank" onmousedown="return nc({'title':this.innerHTML,'url':this.href,'p1':2,'p2':1})">ip138</a></span>
</div>
<script type="text/javascript">
(function(){
加分求答案。
代码是从这个地址来的https://gss0.baidu.com/8aQDcnSm2Q5IlBGlnYG/ipsearch/s?wd=202.108.22.5&tn=baiduip&owd=202.108.22.5调试可以看里面的代码。 展开
</table>
<div id="op_ipmid_res1" class="op_ipmid_res"><span>您查询的IP:<b>202.108.22.5</b></span><span>来自:<b>北京市</b></span><span style="margin:20px;font-size:13px;color:#656565">IP数据提供:<a href="http://www.ip138.com/" target="_blank" onmousedown="return nc({'title':this.innerHTML,'url':this.href,'p1':2,'p2':1})">ip138</a></span>
</div>
<script type="text/javascript">
(function(){
加分求答案。
代码是从这个地址来的https://gss0.baidu.com/8aQDcnSm2Q5IlBGlnYG/ipsearch/s?wd=202.108.22.5&tn=baiduip&owd=202.108.22.5调试可以看里面的代码。 展开
2个回答
展开全部
var
str: AnsiString;
nPos: integer;
begin
str :=
'</table>'
+ '<div id="op_ipmid_res1" class="op_ipmid_res">'
+ '<span>您查询的IP:<b>202.108.22.5</b>'
+ '</span><span>来自:<b>北京市</b></span><span style="margin:20px;font-size:13px;color:#656565">IP数据提供:<a href="http://www.ip138.com/" target="_blank" onmousedown="return nc({''title'':this.innerHTML,''url'':this.href,''p1'':2,''p2'':1})">ip138</a></span>'
+ '</div>'
+ '<script type="text/javascript">'
+ '(function(){';
nPos := pos( '<b>', str );
str := copy( str, nPos );
nPos := pos( '</b>', str );
ShowMessage( copy( str, Length('<b>')+1, nPos-Length('<b>')-1) );
nPos := pos( '<a href="', str );
str := copy( str, nPos );
nPos := pos( '" target', str );
ShowMessage( copy( str, Length('<a href="') + 1, nPos-Length('<a href="') - 1) );
end;
str: AnsiString;
nPos: integer;
begin
str :=
'</table>'
+ '<div id="op_ipmid_res1" class="op_ipmid_res">'
+ '<span>您查询的IP:<b>202.108.22.5</b>'
+ '</span><span>来自:<b>北京市</b></span><span style="margin:20px;font-size:13px;color:#656565">IP数据提供:<a href="http://www.ip138.com/" target="_blank" onmousedown="return nc({''title'':this.innerHTML,''url'':this.href,''p1'':2,''p2'':1})">ip138</a></span>'
+ '</div>'
+ '<script type="text/javascript">'
+ '(function(){';
nPos := pos( '<b>', str );
str := copy( str, nPos );
nPos := pos( '</b>', str );
ShowMessage( copy( str, Length('<b>')+1, nPos-Length('<b>')-1) );
nPos := pos( '<a href="', str );
str := copy( str, nPos );
nPos := pos( '" target', str );
ShowMessage( copy( str, Length('<a href="') + 1, nPos-Length('<a href="') - 1) );
end;
展开全部
有啊
CompareStr就是比较字符串的函数
我举个例子吧
procedure TForm2.FormCreate(Sender: TObject);
const
Str: string = '飘逝的海天 QQ272399954';
Str1: string = '飘逝的海天QQ272399954';
Str2: string = '飘逝的海天 QQ272399954';
begin
if CompareStr(Str, Str1) = 0 then
ShowMessage('str1和str相同')
else
ShowMessage('str1和str不相同');
if CompareStr(Str, Str2) = 0 then
ShowMessage('str2和str相同')
else
ShowMessage('str2和str不相同');
end;
CompareStr就是比较字符串的函数
我举个例子吧
procedure TForm2.FormCreate(Sender: TObject);
const
Str: string = '飘逝的海天 QQ272399954';
Str1: string = '飘逝的海天QQ272399954';
Str2: string = '飘逝的海天 QQ272399954';
begin
if CompareStr(Str, Str1) = 0 then
ShowMessage('str1和str相同')
else
ShowMessage('str1和str不相同');
if CompareStr(Str, Str2) = 0 then
ShowMessage('str2和str相同')
else
ShowMessage('str2和str不相同');
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询