Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my application i am getting email ids as shown below without getting seperated with comma i need to seperate the with comma after
.com using c# code.How can i do this

i am getting the email id's as shown below 

nitya@gmail.combhavya@gmail.com

i need to seperate them after .com using c# code.How can i do this


What I have tried:

i need to seperate them after .com using c# code.How can i do this
Posted
Updated 6-Feb-18 1:26am
Comments
Richard Deeming 8-Feb-18 15:08pm    
You're assuming that your code will only ever be passed email addresses that end with .com; what about other top-level domains?

For example, .co is a valid TLD, associated with Colombia. If you were passed billy@test.comike@test.biz, you'd have no way of knowing whether that was "billy@test.com" and "ike@test.biz", or "billy@test.co" and "mike@test.biz".

The only correct solution is to fix how the email addresses are passed to your application.

1 solution

 
Share this answer
 
Comments
F-ES Sitecore 6-Feb-18 8:39am    
He might find String.Split to be more helpful :)
Maciej Los 6-Feb-18 8:49am    
Kornfeld Eliyahu Peter[^] is right. Check OP's requirements.

string stremails = "nitya@gmail.combhavya@gmail.com";

stremails = stremails.Replace(".com", ".com,");

var emails = stremails.Split(new string[]{","}, StringSplitOptions.RemoveEmptyEntries);

foreach(string e in emails)
{
Console.WriteLine(e);
}
Kornfeld Eliyahu Peter 6-Feb-18 8:55am    
Maybe - It is not clear what OP wants to do with the data after adding the separator...
Let OP decide :-)...

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