cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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

Recommended Articles