如何截取字符串?

来源:百度知道 编辑:UC知道 时间:2024/05/21 07:25:14
比如我获得这样一个字符串
/a.html

我只需要a,把"/"和".html"截取掉,请问怎么实现,用substring
是在.net使用的,比如/a.html,a不是固定的,并且是动态的,可能是aa,可能是aaa

你的意思可能是找出最后一个"/" 与 最后一个"."之间的字符

html=html.Substring(html.LastIndexOf('/')+1,html.LastIndexOf('.')-html.LastIndexOf('/')-1);

string html = "/a.html";
int pos1 = html.find("/")+1;
int pos2 = html.find(".html");
string sstr = html.substr(pos1,pos2-pos1);