Click here to Skip to main content
15,436,928 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have an Input string

"44/1,Cell: +91- 112222112"

my out put string needs to be ""
How i can achieve this in C#
I need to remove all letters up to Mail:

What I have tried:

i tried Indexof()
For Indexof i need to replace "Mail:" with a character then i can get "" using Sub string function
Updated 10-Oct-18 5:58am
Sergey Alexandrovich Kryukov 12-May-16 3:00am     CRLF
Regex! But, honestly, you did not formulate the problem at all. An example is not a formulation. —SA

try this, provided your input will be in this manner ( email at the last)

string input = "44/1,Cell: +91- 112222112";
            string email = input.Substring(input.IndexOf("Mail:")).Replace("Mail:", "");
Share this answer
string testString = "44/1,Cell: +91- 112222112";
string sub = testString.Substring(testString.IndexOf("Mail:") + 5);

Prior to that check this link[^] and this link[^] to understand how two very common String function works.

Hope it helps.
Share this answer
string[] strAry = "44/1,Cell: +91- 112222112".Split(':');

            foreach (var item in strAry)
                bool isEmail = Regex.IsMatch(item, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                if (isEmail)
Share this answer
Richard Deeming 11-Oct-18 10:04am    
Read the question again. The OP was not asking about validating an email address!
use method index of for string..
find first occurance of Mail: you will get the position of M.

string s1="44/1,Cell: +91- 112222112";
int k=s1.IndexOf("Mail:");

then u can use substring method from k+1 index
Share this answer
Richard Deeming 11-Oct-18 10:03am     CRLF
Already covered in solution 2. And your code won't remove the "Mail:" prefix, which the OP didn't want in the output string.

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