str_in_url.m

来自「MAP Toolbox for matlab. World map includ」· M 代码 · 共 35 行

M
35
字号
%STR_IN_URL: This function searches for a string in a html page.
%
%  Syntax>>
%    code_name=str_in_url(url_content2,str_find,limiting_str)
%
%  url_content2 is the content of the html page which is read by using
%     urlread function.
%  str_find is the string which is searched in the html page, i.e. in
%     url_content2 and the string which is actually to be searched exists
%     next to this string and that is code_name.
%  limiting_str is the character which is just next to code_name. 
%   For example, >>>
%   "<img% src=http://www.mathworks.com/matlabcentral/files/authors/1093599.jpg alt="">"
%     image_file=str_in_url(url_content2,'<img src=http://www.mathworks.com/matlabcentral/files/authors/',' ');
%       results in image_file='1093599.jpg'.
%   Another example >>>
%   "Rank: 7<br>"
%     rank=cellstr(str_in_url(url_content2,'Rank: ','<'));
%        results in rank='7'.
% Classes of "url_content2","str_find" and "limiting_str" are char arrays
% Class of "code_name" is char array too.

function code_name=str_in_url(url_content2,str_find,limiting_str)

code_start=findstr(url_content2,str_find)+length(str_find);
code_name='';
empty_code_start=isempty(code_start);
if empty_code_start~=1
for i=0:200
    if url_content2(code_start(1)+i)~=limiting_str
        code_name=[code_name url_content2(code_start(1)+i)];
    else
        break,end
end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?