Home > database > make_valid_struct_key.m

make_valid_struct_key

PURPOSE ^

[str] = make_valid_struct_key(str)

SYNOPSIS ^

function [str] = make_valid_struct_key(str)

DESCRIPTION ^

 [str] = make_valid_struct_key(str)
 
 given str, will replace all non alpha-numeric characters with underscores
 and will append 's' to the beginning of the string
 
 this will construct valid struct field names from any string
 
 NOTE: if you have two strings that are only differentiated by their
 non alpha-numeric characters, this will not maintain their unique
 characters

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [str] = make_valid_struct_key(str)
0002 
0003 % [str] = make_valid_struct_key(str)
0004 %
0005 % given str, will replace all non alpha-numeric characters with underscores
0006 % and will append 's' to the beginning of the string
0007 %
0008 % this will construct valid struct field names from any string
0009 %
0010 % NOTE: if you have two strings that are only differentiated by their
0011 % non alpha-numeric characters, this will not maintain their unique
0012 % characters
0013 %
0014 
0015 % fb 2007/10/29
0016 
0017 % if (~isstr(str))
0018 %     error(sprintf('the variable that you passed is not a string'));
0019 % end
0020 
0021 str = regexprep(str,'\"','');
0022 str = regexprep(str,'[^a-zA-Z0-9]','_');
0023 str = strcat('s',str);

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003