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
fbm73
Level I

script to find and replace portions of character entries in a column

In my data table, I have a column of data type Character with a column name of Size.  The entries for the different rows in column Size are like 8 or so different variations of things like sglLrg500, sglLrg800, sglLrg150, etc.  I would like to have a JMP script that can quickly replace sgl in each of the entries in Size with Sgl instead, so that sglLrg500 for example would become SglLrg500.

 

I could do this manually by selecting the Size column then selecting Edit, Search, Find, and then set Find What to sgl and Replace With to Sgl and check the box for "Restrict to selected columns" and the click Replace All.  But I would like if possible a simple JMP script to do the same thing.  Thanks.

2 REPLIES 2

Re: script to find and replace portions of character entries in a column

Why a script? Have you looked at Cols > Recode?

Dan Obermiller
ih
Super User (Alumni) ih
Super User (Alumni)

Re: script to find and replace portions of character entries in a column

One option is to use regex, it has a pretty steep learning curve but is very powerful:

Regex( :Original Column, "sgl", "Sgl", IGNORECASE, GLOBALREPLACE )

Here is an example table:

New Table( "Replace Example",
	Add Rows( 3 ),
	New Column( "Original", Character, "Nominal", Set Values( {"sglLrg500", "sglLrg800", "sglLrg150"} ) ),
	New Column( "Clean",
		Character,
		"Nominal",
		Formula( Regex( :Original, "sgl", "Sgl", IGNORECASE, GLOBALREPLACE ) ),
		Set Selected,
		Set Display Width( 72 )
	)
)