子串,修剪 [英] Substring, trim

查看:34
本文介绍了子串,修剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我正在尝试使用C#检索电子邮件.我得到了我所需要的一切.但是问题在于消息内容即将来临..

Hi every one.

I am trying to retrieve email by using C#. I got every thing I required. But the problem is the message content is coming like..

--0016367fb7376bfdc30499a12567
Content-Type: text/plain; charset=ISO-8859-1

Your Text message.

--0016367fb7376bfdc30499a12567
Content-Type: text/html; charset=ISO-8859-1



我只需要内容



I need to take only the content

Your Text message.


任何人都可以通过给出逻辑来帮助我,我该如何找回它.
条件是


Can any one please help me out by giving the logic, how can I retrieve it.
The condition is

--0016367fb7376bfdc30499a12567
Content-Type: text/plain; charset=ISO-8859-1



对于不同的邮件可以有所不同,但相同的顺序将是特定顺序的两倍.

在此先感谢.



can be different for different mails but the same will be twice in that particular order.

Thanks in advance.

推荐答案

在主消息前后添加"FIXED"代码.例如:

"A0AKKmasaieTTYYIOIOIMddssPP ...-- ++ yyyYYYY"

您的留言将是:

Add a "FIXED" code before and after your main message. for example:

"A0AKKmasaieTTYYIOIOIMddssPP...--++yyyYYYY"

Your message will be:

--0016367fb7376bfdc30499a12567Content-Type: text/plain; charset=ISO-8859-1


A0AKKmasaieTTYYIOIOIMddssPP...--++yyyYYYYYour Text messageA0AKKmasaieTTYYIOIOIMddssPP...--++yyyYYYY


.--0016367fb7376bfdc30499a12567Content-Type: text/html; charset=ISO-8859-1



现在您已经有了字符串的起点和终点,可以很轻松地删除废物.



Now you have start and end point of your string and it will be simple to delete wastes.


我也写了您必要的方法:

I wrote your necessary method too :

private string FixString(string message)
{
    string[] fixedCode =new string[1] {"A0AKKmasaieTTYYIOIOIMddssPP...--++yyyYYYY"};

    StringSplitOptions option = StringSplitOptions.None;
    string[] messages = message.Split(fixedCode, option);
    for (int i = 0; i < messages.Length;i++ )
    {
        if (i == 1)
            return messages[i];
    }

    return string.Empty;

}



现在,您可以找到您的主要信息:



Now, you can find your main message:

string k = @"--0016367fb7376bfdc30499a12567Content-Type: text/plain; charset=ISO-8859-1
Your Text message.A0AKKmasaieTTYYIOIOIMddssPP...--++yyyYYYYHelloA0AKKmasaieTTYYIOIOIMddssPP...--++yyyYYYY--0016367fb7376bfdc30499a12567Content-Type: text/plain; charset=ISO-8859-1
Your Text message.";
           
Console.WriteLine(FixString(k));


尽管这似乎已解决:

您可以简单地采用前两行并搜索下一个出现的行.该消息将介于两者之间.

-0016367fb7376bfdc30499a12567
内容类型:文本/纯文本; charset = ISO-8859-1


<big>Your Text message.</big>

-0016367fb7376bfdc30499a12567
内容类型:text/html; charset = ISO-8859-1




或者:
您也可以从以下内容的首次出现开始:"Content-Type:".然后,您选择该行之前的那一行,然后再次搜索下一个匹配项.该消息也将介于两者之间.

祝你好运!
Although this seems solved:

You can simply take the first two lines and search for the next occurrence. The message will be in between.

--0016367fb7376bfdc30499a12567
Content-Type: text/plain; charset=ISO-8859-1


<big>Your Text message.</big>

--0016367fb7376bfdc30499a12567
Content-Type: text/html; charset=ISO-8859-1




Alternatively:
You can also start by looking for the first occurrence of: "Content-Type:". Then you take the line before that and that line and again search for the next occurrence. The message will, again also, be in between.

Good luck!


这篇关于子串,修剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆