Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

reverse string

hi all,

if i have strings like this:

value->next_value->next_next_value

item->next_item->next_next_item->next_next_next_item

how can i reverse them, so that i get

next_next_value->next_value_value

next_next_next_item->next_next_item->next_item->item

The strings are of various lengths, but always seperated with '->'

thanks a lot!

1 Reply
Anonymous
Not applicable
Author

In the script you can read them into a new table, with the subfield() function used on the sting to strip it out into its separate elements:

stripped_out_table:

LOAD:

     original_string,                                                  // key back to host table

     rowno() AS sorting_field,

     subfield(original_string,'->') AS string_element

RESIDENT host_table;

This generates a table with one row for each value. Note the rowno() field needed to later sort it.

Join the multiple values stored in this seperate table back onto the host table using a concat() function with the sort field set on it. Something like:

LEFT JOIN (host_table)

LOAD

       original_string,                                        // key to the stripped out table

       concat(string_element,sorting_field) AS reversed_field

RESIDENT stripped_out_table

GROUP BY original_string;

Drop the stripping table afterwards. See attached.

Jonathan