how i can take part of email address

5 vues (au cours des 30 derniers jours)
Mohamuud hassan
Mohamuud hassan le 18 Mai 2015
Modifié(e) : per isakson le 18 Mai 2015
hello all; if i want to take part of email address. for instance, baashe@hotmail.com, suppose i want after @, which means hotmail.com. help me to solve this

Réponse acceptée

per isakson
per isakson le 18 Mai 2015
Modifié(e) : per isakson le 18 Mai 2015
... and with regexp
>> regexp( 'baashe@hotmail.com', '(?<=@).+$', 'match' )
ans =
'hotmail.com'

Plus de réponses (2)

Geoff Hayes
Geoff Hayes le 18 Mai 2015
abdulkarim - you can use strfind or regexp. If the former you could do something like
eAddr = 'baashe@hotmail.com';
idx = strfind(eAddr,'@');
if ~isempty(idx)
domain = eAddr(idx+1:end);
end
  1 commentaire
Mohamuud hassan
Mohamuud hassan le 18 Mai 2015
thank you Hayes. how i can use regexp.

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 18 Mai 2015
Use strfind(). Be sure to make your code robust enough to handle missing @ symbols, and check if @ is in there with isempty.
email = 'baashe@hotmail.com'
atIndex = strfind(email, '@');
if ~isempty(atIndex)
% It's a valid address. Extract the domain.
domain = email(atIndex+1:end);
message = sprintf('The domain is %s', domain);
uiwait(helpdlg(message));
else
% Not a proper email address.
warningMessage = sprintf('%s is not a proper email address', email);
uiwait(warndlg(warningMessage));
end

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by