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

How do we add a whitespace within the string in one of lists of which specific character length bigger than standard form?

For an example;

 

Character Column#1 at row#1: asd 123 deg jkldjsakldjlk 1124

 

if length of any of word within the cell value is bigger than "5", I want a whitespace on the third character.

 

Ideal form is as below

Character Column#1 at row#1: asd 123 deg jkl djsakldjlk 1124

 

thanks,

Joel Ahn
Lam Research Corporation
Mobile +82 10 9509 0109
3 REPLIES 3
jthi
Super User

Re: How do we add a whitespace within the string in one of lists of which specific character length bigger than standard form?

One way would be to use Regex.

 

This might work:

Names Default To Here(1);

line = "asd 123 deg jkldjsakldjlk 1124";
span_line = Regex(line, "([a-zA-Z0-9]{3})([a-zA-Z0-9]{3,})", "\1 \2", GLOBALREPLACE);
show(span_line == "asd 123 deg jkl djsakldjlk 1124");

line = "1 22 333 4444 55555 666666 7777777 88888888 999999999 0000000000";
span_line = Regex(line, "([a-zA-Z0-9]{3})([a-zA-Z0-9]{3,})", "\1 \2", GLOBALREPLACE);
show(span_line);

https://regex101.com/r/CuxFKx/1 

 

-Jarmo
txnelson
Super User

Re: How do we add a whitespace within the string in one of lists of which specific character length bigger than standard form?

Here is one way of doing what you want

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

For Each Row(
	holdString = "";
	wordNum = 1;
	While( Word( wordNum, :column 1, " " ) != "",
		theWord = Word( wordNum, :column 1, " " );
		If( Length( theWord ) > 5,
			theWord = Substr( theWord, 1, 3 ) || " " || Substr( theWord, 4 )
		);
		holdString = holdString || " " || theWord;
		wordNum++;
	);
	:Column 1 = Trim( holdString );
Jim

Re: How do we add a whitespace within the string in one of lists of which specific character length bigger than standard form?

I am not sure if you an interactive, a formula, or a scripted solution. The Cols > Recode command provides a rich tool for changing values in a column. See examples and instructions for Recode here.

Recommended Articles