Click here to Skip to main content
16,011,779 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everybody,

I am parsing email Ids from body of content of the email. while parsing a body of content having richa@carteworld.com as email Id it is taken 3Aricha@carteworld.com. I dig through the problem and came to know that there is a invisible character which i can't able to find in the body of the content (i.e. there may be character in the body of content which may not be part of the email id but it will in body of content) so it picks up like this. can any one help me out to cut all unwanted charactes in the body of content text.

eager waiting for earliest replies


regard
Kumaran
Posted
Updated 20-Jan-10 22:29pm
v2

If you know what the character(s) is(are) you can try something like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            char EvilHiddenChar = (char)3;
            string EmailMessage = string.Format("Hello{0}, this {0}is my {0}E-mail message", EvilHiddenChar);
            Console.WriteLine(EmailMessage);
            EmailMessage = EmailMessage.Replace(EvilHiddenChar.ToString(), String.Empty);
            Console.WriteLine(EmailMessage);
            Console.ReadLine();
        }
    }
}


Hope this helps :cool:
 
Share this answer
 
v3
There are various approaches you could take. If you know the characters you want to cut out, you can use string.Split to remove the characters and then string.Concat to recombine the string that you just split. Alternatively, if you only know the characters you want to keep (a-z, 0-9, punctuation, and so on), then you can use a regular expression to find all characters that do not match those characters and you could call Regex.Replace to remove any matches. That would go something like this:
C#
string input = "This is some string where I only want letters and numbers.";
string pattern = "((?![a-z]|[0-9]).)+";
string result = Regex.Replace(input, pattern, string.Empty);

I will leave it to you to construct the exact regular expression you want.
 
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