How to remove leading characters (::) and ending characters (;;) from a column name in a data setHey, can you please give me an advice how to remove certain signs like :: at the beginning and ;; at the end of a column names, if available.
Example:
::ColumnName;; --> ColumnName
::ColumnName::XYZ;ABC;; --> ColumnName::XYZ;ABC
123::ColumName --> no change 123::ColumName
Data TableScriptingWindowsRe: How to remove leading characters (::) and ending characters (;;) from a column name in a data setHere is a simple script that will do what you want
Names Default To Here( 1 );
dt = Current Data Table();
For( i = 1, i <= N Cols( dt ), i++,
theName = Column( dt, i ) << get name;
If( Left( theName, 2 ) == "::",
theName = Substr( theName, 3 )
);
If( Right( theName, 2 ) == "::",
theName = Substr( theName, 1, Length( theName ) - 2 )
);
Column( dt, i ) << set name( theName );
);
Re: How to remove leading characters (::) and ending characters (;;) from a column name in a data setCouple of additional options for name building
// Option1, using Starts With, Ends With and Substr
If(Starts With(col_name, "::"),
col_name = Substr(col_name, 3);
);
If(Ends With(col_name, ";;"),
col_name = Substr(col_name, 1, Length(col_name) - 2);
);
Not sure if this works in all cases
// Option2, using Regex
regex_pattern = "(?:^::)(.*)(?:;;$)";
Regex(col_name, regex_pattern, "\1");