Suppose I have a string of characters with common delimiter in a form of bal1_bla2_blbla3_blabla4
And I would like to create a new column that contains only "blbla3_blabla4", how can I apply words function for that?
Hi,
one solution in the UI would be to use Recode to achieve what you are aiming for.
Right click on your column header -> Recode -> right click on the red triangle under new value -> Advanced -> extract segment
You can find the JSL code in the log and it is using the word function:
/*: // Recode column: Column 1 2 Local( {dt, col1}, dt = Data Table( "Test table" ); dt << Begin Data Update; col1 = dt << New Column( dt:Column 1 ); col1 << Set Name( "Column 1 2" ); dt << Move Selected Columns( {col1}, after( dt:Column 1 ) ); For Each Row( dt, col1[] = Word( [3 4], dt:Column 1, Get Whitespace Characters() || Get Punctuation Characters( Exclude Chars( "'-" ) ) || "_", Unmatched( dt:Column 1 ) ) ); dt << End Data Update;
Hope this helps.
Jonas
If you want two last elements, then you can use Word with negative indexing (or positive if you know the exact locations from the beginning of the string)
Names Default To Here(1); str = "bal1_bla2_blbla3_blabla4"; res = Word([-2 -1], str, "_"); Show(res); // res = "blbla3_blabla4";