Finding a specific character in a string in Matlab

前端 未结 7 1230
闹比i
闹比i 2020-12-16 13:02

Suppose I have a string \'johndoe@hotmail.com\'. I want to store the string before and after \"@\" into 2 separate strings. What would be the easiest method of

7条回答
  •  轮回少年
    2020-12-16 13:17

    If this thread isn't completely enumerated by now, may I add another? A handy perl-based MATLAB function:

    email = 'johndoe@hotmail.com';
    parts = regexp(email,'@', 'split');
    

    parts is a two element cell array similar to mtrw's implementation of textscan. Maybe overkill, but regexp is much more useful when splitting a string by multiple delimiting characters or pattern searching. The only downside is the use of regular expressions which I still haven't mastered after 15 years of coding.

提交回复
热议问题