cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Greenhorn
Level III

How to remove leading characters (::) and ending characters (;;) from a column name in a data set

Hey, 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

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to remove leading characters (::) and ending characters (;;) from a column name in a data set

Here 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 );
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: How to remove leading characters (::) and ending characters (;;) from a column name in a data set

Here 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 );
);
Jim
jthi
Super User

Re: How to remove leading characters (::) and ending characters (;;) from a column name in a data set

Couple 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");
-Jarmo