Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 在Matlab中查找字符串中的特定字符_String_Matlab - Fatal编程技术网

String 在Matlab中查找字符串中的特定字符

String 在Matlab中查找字符串中的特定字符,string,matlab,String,Matlab,假设我有一个字符串'johndoe@hotmail.com“。我想将“@”前后的字符串存储到两个单独的字符串中。查找字符串中的“@”字符或其他字符的最简单方法是什么?对于“最简单的” 如果您正在查找具有多个字符的内容,或者您不确定是否只有一个@,那么情况会稍微复杂一些,在这种情况下,MATLAB有很多用于搜索文本的函数,包括正则表达式(请参见doc regexp).我使用了Matlab中的strtok和strrep。索引操作应该可以做到: str = 'johndoe@hotmail.com';

假设我有一个字符串
'johndoe@hotmail.com“
。我想将“@”前后的字符串存储到两个单独的字符串中。查找字符串中的“@”字符或其他字符的最简单方法是什么?

对于“最简单的”


如果您正在查找具有多个字符的内容,或者您不确定是否只有一个@,那么情况会稍微复杂一些,在这种情况下,MATLAB有很多用于搜索文本的函数,包括正则表达式(请参见
doc regexp
).

我使用了Matlab中的strtok和strrep。

索引操作应该可以做到:

str = 'johndoe@hotmail.com';
[name,address] = strtok(str,'@');
address = address(2:end);
或者最后一行也可以是:

address(1) = '';
也行

str = 'johndoe@hotmail.com';
parts = textscan(str, '%s %s', 'Delimiter', '@');

返回一个单元格数组,其中部分{1}为'johndoe',部分{2}为'hotmail.com'。

您可以使用stread:

str = 'johndoe@hotmail.com';
[a b] = strread(str, '%s %s', 'delimiter','@')
a = 
    'johndoe'
b = 
    'hotmail.com'
字符串电子邮件=”johndoe@hotmail.com";

String a[]=email.split(“@”);
字符串def=null;
字符串ghi=null;

对于(int i=0;i如果这个线程现在还没有完全枚举,我可以添加另一个吗?一个方便的基于perl的MATLAB函数:

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

parts是一个两元素的单元数组,类似于mtrw的textscan实现。可能有些过激,但当用多个定界字符分割字符串或进行模式搜索时,regexp更有用。唯一的缺点是使用正则表达式,我在编码15年后仍然没有掌握它。

-1。其他答案是这里更好,因为他们提供了示例代码。您是如何使用
strtok
strep
?显示一个示例,我将转到+1.+1奇怪的是,一直没有人提到正则表达式:)注意:最近版本的MATLAB建议使用
textscan
而不是
stread
    String a[] = email.split("@");
    String def = null;
    String ghi = null;
    for(int i=0;i<a.length;i++){
        def = a[0];
        ghi = a[1];
    }
email = 'johndoe@hotmail.com';
parts = regexp(email,'@', 'split');