另一种方法是使用String.Split: private string [] splitString = new string [] { @ - = _ NextPart_SMP _}; private List< string> getSections( string source) { return source.Split(splitString,StringSplitOptions .RemoveEmptyEntries).ToList(); } // 在方法中测试正文 私人 字符串 source = @ 您的测试内容在这里; List< string> result = getSections(source); if (result == null ) throw new EvaluateException( 无法解析来源!); for ( int i = 0 ; i < result.Count; i ++) { Console.WriteLine( Section:{0}值:{1},i.ToString(),result [i]); } 请看下面的例子。 string pattern = - = _ NextPart_SMP(?< result>。*) - = _ NextPart_SMP; 正则表达式正则表达式= 新正则表达式(模式); 匹配匹配= regex.Match( - = _ NextPart_SMP_1d0087c4c718772_aee00768_00000001 - = _ NextPart_SMP); if (match.Success) { string result = match.Groups [ RESULT]。值; } 这将给你_1d0087c4c718772_aee00768_00000001 祝你好运, Stephan I need to find all the lines between "--=_NextPart_SMP_" using c#--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001Content-Type: image/jpegContent-Transfer-Encoding: base64Content-Location: screenshot_0001.jpeg/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQV1ZkcJB6ZGqIbFZXfap+iJSZoaKhYXiwva+cu5CeoZr/2wBDARscHCUhJUkpKUmaZ1dnmpqampqampqampqampqampqampqampqampqampqampqampqampqampqampqampqampr/wAARCAQABQADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001 解决方案 If you want, you can use some available library to parse mail messages. I would recommend open-source OpenPop.NET:http://sourceforge.net/projects/hpop[^].This library is not perfectly well written, but it thoroughly works with all those MIME standards and contains a POP3 client in the code. You can use it directly, or simply use as a reference, which is also useful.—SAAnother alternative is to use String.Split:private string[] splitString = new string[]{@"--=_NextPart_SMP_"};private List<string> getSections(string source){ return source.Split(splitString, StringSplitOptions.RemoveEmptyEntries).ToList();}// test in a method bodyprivate string source = @"Your test content goes here";List<string> result = getSections(source);if(result == null) throw new EvaluateException("can't parse source !");for (int i = 0; i < result.Count; i++){ Console.WriteLine("Section: {0} Value: {1}",i.ToString(),result[i]);}Hi,please have a look at the following example.string pattern = "--=_NextPart_SMP(?<result>.*)--=_NextPart_SMP";Regex regex = new Regex(pattern);Match match = regex.Match("--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001--=_NextPart_SMP");if(match.Success){ string result = match.Groups["RESULT"].Value;}This will give you "_1d0087c4c718772_aee00768_00000001"Best regards,Stephan 这篇关于如何使用C#在记事本中的两行之间查找文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 19:23