matlab.lang.makevalidname
构造有效MATLABidentifiers from input strings
Syntax
描述
构建有效的MATLAB®identifiers,N
= matlab.lang.makevalidname(S
)N
, from input strings,S
。这makevalidname
function does not guarantee the strings inN
是独一无二的。
有效的MATLAB标识符是字母数字(A – Z,A – Z,0-9)和下划线的字符向量,因此第一个字符是字母,字符的长度小于或等于namelengthmax
。
makevalidname
deletes any whitespace characters before replacing any characters that are not alphanumerics or underscores. If a whitespace character is followed by a lowercase letter,makevalidname
将字母转换为相应的大写字符。
includes additional options specified by one or moreN
= matlab.lang.makevalidname(S
,Name,Value
)Name,Value
配对参数。
例子
Input Arguments
Output Arguments
提示
为确保输入值有效且唯一,请使用
matlab.lang.makeUniqueStrings
aftermatlab.lang.makevalidname
。S = {'my.Name','my_Name','my_Name'};有效values = matlab.lang.lang.makevalidname(s)valluniqueValues = matlab.lang.makeuniquestress(varrevalues,{},。。。namelengthmax)
validValues = 'my_Name' 'my_Name' 'my_Name' validUniqueValues = 'my_Name' 'my_Name_1' 'my_Name_2'
To customize an invalid character replacement, first use functions such as
strrep
或者REGEXPrep
转换为有效字符。例如,转换'@'
字符中S
to'At'
usingstrrep(s,'@','at')
。然后,使用matlab.lang.makevalidname
确保所有字符S
are valid.
See Also
iskeyword
|isletter
|ISVARNAME
|matlab.lang.makeUniqueStrings
|namelengthmax
|REGEXP
|REGEXPrep
|strrep
|谁