nelson.lang.makeValidName
Convert text to valid Nelson variable names.
📝Syntax
N = nelson.lang.makeValidName(S)
N = nelson.lang.makeValidName(S, 'ReplacementStyle', style)
N = nelson.lang.makeValidName(S, 'Prefix', prefix)
[N, modified] = nelson.lang.makeValidName(...)
📥Input Arguments
Parameter Description
S string array, character vector, or cell array of character vectors.
style replacement style: 'underscore', 'delete', or 'hex'.
prefix valid variable name used when a generated name does not start with a letter.
📤Output Arguments
Parameter Description
N valid names, returned with the same text container type as S.
modified logical array indicating which input elements were changed.
📄Description

nelson.lang.makeValidName removes whitespace, replaces unsupported characters, adds a prefix when needed, and truncates names to namelengthmax.

💡Examples
names = nelson.lang.makeValidName({'a b', 'a-b', '1a'})
[names, modified] = nelson.lang.makeValidName("a#b", 'ReplacementStyle', 'hex')
🔗See Also
isvarnamenelson.lang.makeUniqueStringsnamelengthmax
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub