2-34.m
来自「《MATLAB 7.0编程基础基础》源程序」· M 代码 · 共 39 行
M
39 行
s = 'Find the starting indices of the shorter string.';
findstr(s,'the')
findstr('the',s)
strfind(s, 'in')
strfind(s, 'In')
% 区别大小写,返回空数组
strfind('in',s)
% strfind函数的第二个字符串作为查询的子串
% 创建字符元胞数组
idx = strfind(cstr, 'wood');
% 在元胞数组中查询子串
idx{:,:}
s = ' This is a simple example.';
[token, rem] = strtok(s)
% 返回两个参量,token为默认空格前的字符子串,而rem而为剩下的子串
s1 = 'This is a good example.';
str = strrep(s1, 'good', 'great')
% 把'good'置换成'great'
x = strmatch('max', strvcat('max', 'minimax', 'maximum'))
% 在多行字符串中查询匹配的字符串,存在返回行号
x = strmatch('max', strvcat('max', 'minimax', 'maximum'),'exact')
% 查询绝对匹配的字符串
str = 'Romeo and Juliet';
s1 = regexp(str, '[A-Z]')
% 查询匹配A-Z大写字母的位置
s2 = regexp(str, '\s')
% 查询空格的位置,可以完全实现findstr函数的功能
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?