C#字符串截取问题

kkz66hc 2009-03-05 03:25:24
content=需要截取的字符串
b=查到到的开头(结果不包含他)
e=(左到右查到的第一次内容,结果不包含他)
asp我写法如下

Function Getstr(content,b,e)
IF instr(content,b)<>0 or instr(content,e)<>0 then
w=instr(content,b)
getstrtemp=mid(content,w+len(b))
If instr(getstrtemp,e)-1>0 then getstr=left(getstrtemp,instr(getstrtemp,e)-1)
end if
End Function

C#要怎么写呢
用来做(小偷)采集程序的
按开头与结尾截取出需要的内容!
各位大大帮忙!
...全文
63 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgke 2009-03-05
  • 打赏
  • 举报
回复
private string Getstr(string content,string b,string e)
{
int _StarIndex =content.IndexOf(b);
if(_StarIndex==-1)return "";
_StarIndex++;
int _EndIndex =content.IndexOf(e,_StarIndex);
if(_EndIndex==-1)return"";
return content.Substring(_StarIndex,_EndIndex-_StarIndex);

}
sy_binbin 2009-03-05
  • 打赏
  • 举报
回复
你查查IndexOf()和Substring()的用法

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧