Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
2.78/5 (3 votes)
See more:
hii
i have a string abc@gmail.com
i want to extract only gmail from it
how can i search of index till i reach @ and how can i search for index till i get .
and then i extract gmail from it..
help
Posted
Updated 4-Jul-13 7:29am
v2
Comments
[no name] 4-Jul-13 13:31pm    
Have you tried IndexOf?

First of all, if you cannot extract a substring from a string not asking any questions, you are not ready to work with mail and any other advanced stuff, including UI. You should do elementary exercises in programming basics using simplest console-only applications, which should take considerable amount of time.

In this case, you could use string.Split:
http://msdn.microsoft.com/en-us/library/system.string.split.aspx[^],
http://msdn.microsoft.com/en-us/library/system.string.aspx[^].

—SA
 
Share this answer
 
Comments
Rajan Maheshwari 4-Jul-13 13:40pm    
string email_id = TextBox1.Text;
index1 = email_id.IndexOf('@');
index2 = email_id.IndexOf('.');
email_id = email_id.Substring(index1 + 1);
but here i only get upto gmail.com
how to remove .com from it.coz i cant work with text length as the ids canbe live.com hotmail.com etc etc
[no name] 4-Jul-13 13:45pm    
Yes you would have to SubString again using index2....
Sergey Alexandrovich Kryukov 4-Jul-13 13:53pm    
It looks like you did not read my answer. Don't do it.
Also, such question does not deserve any discussion. You need to do it all by yourself, just reading MSDN documentation.
—SA
Rajan Maheshwari 4-Jul-13 13:49pm    
but the problem is substring have only two overloaded methods in which we cant delete a string from back...
it has (int len)
(int len,start index)
Sergey Alexandrovich Kryukov 4-Jul-13 13:55pm    
You don't understand one basic thing: nothing can delete anything from a string. Strings are immutable. Surprise?
—SA
C#
string Source = "abc@gmail.com";
char[] dest;
Source.CopyTo(3 ,dest,0,4);
console.write(Source);
console.writeline(dest);
 
Share this answer
 
v2
Comments
Rajan Maheshwari 4-Jul-13 14:47pm    
btw i have solved it but again u never know what is the email address
If i enter abcdef@gmail.com ur above code is failed............
yeah i know what is email you should try it
C#
string s = "sk.shrinet@gmail.com";

           string[] words = s.Split('@');
           foreach (string word in words)
           {
               Console.WriteLine(word);
           }
 
Share this answer
 
Comments
Rajan Maheshwari 5-Jul-13 6:42am    
this also only gives gmail.com
I only want gmail to be printed.........

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