如何在 MATLAB 中删除字符串中的空格?
在本文中,我们将讨论如何借助 isspace()、find()、strrep() 和
regexprep() 函数从 MATLAB 中的字符串中删除空格。
使用 isspace()
isspace()函数用于识别是 ASCII 空白的元素。isspace('string')用于
查找指定“string”中存在的空格。
句法:
isspace(‘string’)
示例 1:
% MATLAB code for Space removal in
% string using isspace()
% Initializing a string
String = 'G F G';
% Calling the find() function
% along with isspace() function
% over the above string to remove
% the white spaces
New_String = String(find(~isspace(String)))
输出:
New_String = GFG
示例 2:
% MATLAB code for replacing space with
% null using the
% isspace() function
% Initializing a string
String = 'G e e k s f o r G e e k s';
评论0
最新资源