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
kuanaunwei
Level III

How do i rename column header name with existing string?

Hi,

 

I am trying to rename multiple column header name that consists a particular string but rename it with the existing string while remove the front portion of the string.

 

Example:

 

ABC_12::ABCD_AB_ABCDEF_A_ABCDE_X_X_A1_1234_ABCD_TESTING_AB_TEST_ABCD_TESTED_AB_A1 --> TESTING_AB_TEST_ABCD_TESTED_AB_A1

 

The number of character on the first part of the string (orange) will always be consistent, the 2nd portion of the string will vary from 1 to another. 

 

What have i done so far is the below:

 

dt=current data table();

colList = dt << get column names( string );

For( i = 1, i <= N Items( colList ), i++,
	If( Left( colList[i], 50 ) == "ABC_12::ABCD_AB_ABCDEF_A_ABCDE_X_X_A1_1234_ABCD",
		Column( dt, colList[i] ) << Substr((colList[i],50) ), // this is the part where i m stuck.
	)
);

I have tried using Trim & Left. But it does not work. I have an idea of using "set name" to take in string after the 50th character. But must have a better way on doing this.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do i rename column header name with existing string?

You need to use  

<< set name 

to change the name of the column

Names Default To Here( 1 );
dt = Current Data Table();

colList = dt << get column names( string );

For( i = 1, i <= N Items( colList ), i++,
	If( Left( colList[i], 48 ) == "ABC_12::ABCD_AB_ABCDEF_A_ABCDE_X_X_A1_1234_ABCD_",
		Column( dt, colList[i] ) << set name( Substr( colList[i], 49 ) ), // this is the part where i m stuck.
	)
);

 

Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: How do i rename column header name with existing string?

You need to use  

<< set name 

to change the name of the column

Names Default To Here( 1 );
dt = Current Data Table();

colList = dt << get column names( string );

For( i = 1, i <= N Items( colList ), i++,
	If( Left( colList[i], 48 ) == "ABC_12::ABCD_AB_ABCDEF_A_ABCDE_X_X_A1_1234_ABCD_",
		Column( dt, colList[i] ) << set name( Substr( colList[i], 49 ) ), // this is the part where i m stuck.
	)
);

 

Jim