字符串截取问题,在线等! ( 积分: 50 )

  • 主题发起人 主题发起人 macrolen
  • 开始时间 开始时间
M

macrolen

Unregistered / Unconfirmed
GUEST, unregistred user!
<input type="hidden" name="__VIEWSTATE" value="dDwtMTg4MjY4NzEwMS1iVNgFcg==" />
我现在想截取.net页面中ViewState的value中的值,如上。

但是我用 GetStr(TempStr,'__VIEWSTATE" value="', '=" />'); 就可以截取的到
可是把结束字符中的等号去掉就不行了,是什么原因?该怎么解决呢?

我使用的截取函数是这样:
function GetStr(StrSource, StrBegin, StrEnd:String): String;
var
in_star, in_end : integer;
begin
in_star := AnsiPos(strbegin, strsource) + length(strbegin);
in_end := AnsiPos(strend, strsource);
result := Copy(strsource, in_star, in_end-in_star);
end;
 
没明白你的意思!

你是说
GetStr(TempStr,'__VIEWSTATE" value="', '" />');
这样??

可以截取啊
 
GetStr(TempStr,'__VIEWSTATE" value="', '" />');
是这样,但是ViewState值很长的时候,什么也截不到,但是结束符再多个字符又可以截到,晕!
 
你给一个取不到的值!

我看看!!
 
这个:
<input type="hidden" name="__VIEWSTATE" value="dDwtMTg4MjY4NzEwMzt0PHA8bDxVc2VyRmlsZVZpcnR1YWxQYXRoO1VzZXJGaWxlUGh5c2ljYWxQYXRoO01heFNwYWNlU2l6ZTtVcGRhdGVJbWFnZVNpemU7UGFnZUluZGV4O1BhZ2VOdW1iZXI7VXNlclRvdGFsRmlsZVNpemU7PjtsPC9Vc2VyRmlsZXMveC94aS94aWEveGlhb2tla2UuaXQuY29tLmNuL2ZpbGVzLztcXFxcMjE5LjIzOS45NC40NlxcaXRfaG9tZVxceFxceGlcXHhpYVxceGlhb2tla2UuaXQuY29tLmNuXFxmaWxlc1xcO2k8NTEwNjU+OzIwMDA7aTwxPjtpPDM+Ozk5MDk7Pj47bDxpPDE+Oz47bDx0PHA8bDxlbmN0eXBlOz47bDxtdWx0aXBhcnQvZm9ybS1kYXRhOz4+O2w8aTwxPjtpPDM+O2k8NT47aTwxNT47PjtsPHQ8QDA8cDx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hpYW9rZWtlOzIwMDY2MTQ5Mzc4X3NtYWxsLmpwZztmYWNlLmpwZzs+Ozs+Oz4+O3Q8O2w8aTwwPjs+O2w8dDxAPDIwMDY2MTQ5MTI0Ny5KUEc7eGlhb2tla2U7MjAwNjYxNDkxMjQ3LkpQRzt4aWFva2VrZTsyMDA2NjE0OTEyNDdfc21hbGwuSlBHO0hPTUUuSlBHOz47Oz47Pj47Pj47dDxwPGw8VmlzaWJsZTs+O2w8bzxmPjs+Pjs7Pjt0PDtsPGk8MD47PjtsPHQ8O2w8aTwxPjtpPDM+O2k8NT47aTw3PjtpPDk+O2k8MTU+Oz47bDx0PHA8cDxsPFRleHQ7PjtsPDg1Oz4+Oz47Oz47dDxwPHA8bDxUZXh0Oz47bDwxOz4+Oz47Oz47dDxwPHA8bDxUZXh0Oz47bDwzOz4+Oz47Oz47dDxwPHA8bDxFbmFibGVkOz47bDxvPGY+Oz4+Oz47Oz47dDxwPHA8bDxFbmFibGVkOz47bDxvPGY+Oz4+Oz47Oz47dDxwPGw8ZGlzYWJsZWQ7PjtsPDs+Pjs7Pjs+Pjs+Pjt0PHA8bDxpbm5lcmh0bWw7PjtsPOaCqOWPr+eUqOeahOaAu+epuumXtOS4ujUxMDY1S++8jOebruWJjeW3suS9v+eUqDk5MDlLOz4+Ozs+Oz4+Oz4+Oz7R3DxiwaIDUafXh6hAUOlTiK0x6A==" />
 
晕啊

可以取道!
 
我是先get一个页面从里面取,例如:
idHTTP:= TidHTTp.create(nil);
try
TempStr := idhttp.Get('http://bbs.it.com.cn/ShowPost.aspx?TopicID=73450');
ViewState:= GetStr(TempStr, '__VIEWSTATE" value="','" />');
这个页面的ViewState值比较短,可是还是取不到,哭.......
 
function GetStr(StrSource, StrBegin, StrEnd:String): String;
var
in_star, in_end : integer;
begin
in_star := AnsiPos(strbegin, strsource) + length(strbegin);
Delete(StrSource, 1,In_Star-1);
in_end := AnsiPos(strend, strsource);
result := Copy(strsource, 1, in_end);
end;

改成差不多上面这样就可以了,理由很简单,你的结束字符在开始字符之前还存在,根据你提供的网址,可以得到开始字符是9百多,而结束的位置是8百多,试想
Copy(strsource, 900, -100)能取到什么字符呢?
 
顺便建议一句,下次碰到问题要追踪一下代码,这一跟踪不就出来了,结束位置比起始位置小,显然取不到字符嘛。

而且也说明一个问题,考虑欠妥当,试想 " />' 的短字符串,在整个网页中出现的频率是很高的。这也就是你说的,再加两等号就能取到的原因。
 
非常感谢levi的热心回答,原来是这样,问题解决了,哈哈,好开心呀[:D]
 
后退
顶部