问题描述
如何在一大字符串中截取以下这两段字符串?第二段字符串中间有换行,听说一般都用正则来截取,如何实现?谢谢!filename="=?GBK?Q?=B0=D7=D6=A4.dwg?="filename="=?GBK?Q?11-25=D5=C5=C1=C1=D7=AA90=D7=F8?==?GBK?Q?=B1=EA=B4=F808=C4=EA=B8=DF=B3=CC.txt?="
解决方案
解决方案二:
StringstrToSearch="";if(str.ToSearch.IndexOf(fileName)!=-1){DoSth();}
有换行就用n吧,没试过
解决方案三:
题目不清晰,请重新举个例子说明一下,关键是明确输入,输出。
解决方案四:
我举个例子,比如在如下的2个文本里截取Content-Type:application/octet-stream;name="=?GBK?Q?=B0=D7=D6=A4.dwg?="Content-Transfer-Encoding:base64Content-Disposition:attachment;filename="=?GBK?Q?=B0=D7=D6=A4.dwg?="在这文本里我想截取filename="=?GBK?Q?=B0=D7=D6=A4.dwg?="Content-Type:text/plain;name="=?GBK?Q?11-25=D5=C5=C1=C1=D7=AA90=D7=F8?==?GBK?Q?=B1=EA=B4=F808=C4=EA=B8=DF=B3=CC.txt?="Content-Transfer-Encoding:base64Content-Disposition:attachment;filename="=?GBK?Q?11-25=D5=C5=C1=C1=D7=AA90=D7=F8?==?GBK?Q?=B1=EA=B4=F808=C4=EA=B8=DF=B3=CC.txt?="在这文本里我想截取filename="=?GBK?Q?11-25=D5=C5=C1=C1=D7=AA90=D7=F8?==?GBK?Q?=B1=EA=B4=F808=C4=EA=B8=DF=B3=CC.txt?="
解决方案五:
stringstr22="Content-Type:application/octet-stream;name="=?GBK?Q?=B0=D7=D6=A4.dwg?="Content-Transfer-Encoding:base64Content-Disposition:attachment;filename="=?GBK?Q?=B0=D7=D6=A4.dwg?="";foreach(MatchmatchinnewRegex("filename="[^"]*"").Matches(str22)){Console.WriteLine(match);}
解决方案六:
我自己写的方法哈。。。publicstaticstringGetStartEndStr(stringsource,stringstart,stringend){stringstr="";intlen1=source.IndexOf(start);if(len1>-1){stringcutstr=source.Substring(len1+(start).Length);intlen2=cutstr.IndexOf(end);str=cutstr.Substring(0,len2);}returnstr;}调用GetStartEndStr(str,"filename="",""");得到的结果是=?GBK?Q?11-25=D5=C5=C1=C1=D7=AA90=D7=F8?==?GBK?Q?=B1=EA=B4=F808=C4=EA=B8=DF=B3=CC.txt?=
解决方案七:
截取的东西有规律吗比如说有无特殊符号能表示出所要取得东西,或者所取得字符串的长度和位置