Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to find all the lines between "--=_NextPart_SMP_" using c#


--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001

Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0001.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
V1ZkcJB6ZGqIbFZXfap+iJSZoaKhYXiwva+cu5CeoZr/2wBDARscHCUhJUkpKUmaZ1dnmpqampqa
mpqampqampqampqampqampqampqampqampqampqampqampqampqampqampr/wAARCAQABQADASIA
AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Posted
Updated 1-Dec-14 3:50am
v2

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.

—SA
 
Share this answer
 
Comments
Maciej Los 1-Dec-14 14:44pm    
5ed!
Sergey Alexandrovich Kryukov 1-Dec-14 21:41pm    
Thank you, Maciej.
—SA
Maria Lopez 7-Dec-14 7:34am    
+5
Sergey Alexandrovich Kryukov 7-Dec-14 12:02pm    
Thank you, Maria.
—SA
Another alternative is to use String.Split:
C#
private string[] splitString = new string[]{@"--=_NextPart_SMP_"};

private List<string> getSections(string source)
{
    return source.Split(splitString, StringSplitOptions.RemoveEmptyEntries).ToList();
}


// test in a method body

private 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]);
}
 
Share this answer
 
v2
Comments
TheRealSteveJudge 2-Dec-14 2:49am    
Elegant solution. 5 stars
Renjith_R 2-Dec-14 5:19am    
--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0004.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
kfeUHJ6sB3NBChWO9Pun+IelID//2Q==

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0005.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
wHc0EKFY70+6f4h6UgP/2Q==

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0006.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
uxZjknk0wKjLkn6n+ZoC8H/dP8qmAUj7yg5PVgO5oIUKx3p90/xD0pAf/9k=

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0007.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
/M0BeD/un+VTAKR95QcnqwHc0EKFY70+6f4h6UgP/9k=

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0009.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
zwMYpkkrSY3Y44GFA/lSOxdizHJPJpgVGXJP1P8AM0BeD/un+VTAKR95QcnqwHc0EKFY70+6f4h6
UgP/2Q==

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001--


I need to get the decoded characters like /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
kfeUHJ6sB3NBChWO9Pun+IelID//2Q== from the above text documents
TheRealSteveJudge 2-Dec-14 8:16am    
I tried this solution and it definitely works!
Hi,

please have a look at the following example.

C#
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
 
Share this answer
 
v2
Comments
Renjith_R 1-Dec-14 10:45am    
While debugging the above code am Getting result as Null, Actually this is a test document contain more than 10 + section starts with "--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001", I need to get all the section between each "--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001"
BillWoodruff 1-Dec-14 19:31pm    
"this is a test document contain more than 10 + section starts with:" that's the kind of important information you should include in your question.
TheRealSteveJudge 1-Dec-14 10:51am    
OK. That is a different case.
Can you post the complete test document?
Renjith_R 2-Dec-14 5:14am    
--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0004.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
kfeUHJ6sB3NBChWO9Pun+IelID//2Q==

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0005.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
wHc0EKFY70+6f4h6UgP/2Q==

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0006.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
uxZjknk0wKjLkn6n+ZoC8H/dP8qmAUj7yg5PVgO5oIUKx3p90/xD0pAf/9k=

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0007.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
/M0BeD/un+VTAKR95QcnqwHc0EKFY70+6f4h6UgP/9k=

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Location: screenshot_0009.jpeg

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
zwMYpkkrSY3Y44GFA/lSOxdizHJPJpgVGXJP1P8AM0BeD/un+VTAKR95QcnqwHc0EKFY70+6f4h6
UgP/2Q==

--=_NextPart_SMP_1d0087c4c718772_aee00768_00000001--
Renjith_R 2-Dec-14 5:15am    
I need to get the decoded characters like /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0+WlBfXllQ
kfeUHJ6sB3NBChWO9Pun+IelID//2Q== from the above text documents
Try a regex:
(--=_NextPart_SMP_)(.*)(?=--=_NextPart_SMP_)
Should do it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900