Command help

Skip to first unread message

David Roth

Nov 3, 2022, 9:45:40 AM11/3/22
to OpenRefine

I am trying to use OpenRefine to flip names from First Last to Last, First. Command value.split(',')[1] + ' ' + value.split(',')[0] yielded Error: java.lang.ArrayIndexOutOfBoundsException: 1. What else can I try? Thanks.

All the best,

Owen Stephens

Nov 4, 2022, 6:27:00 AM11/4/22
to OpenRefine
Hi David,

The java.lang.ArrayIndexOutOfBoundsException: 1 error means that you are attempting to access an element in an array that doesn't exist

The expression:
value.split(',')[1] + ' ' + value.split(',')[0]

Will work for strings that have a comma in them, but any string without a comma will give the out of bounds error because in that case the 'split' will create  an array with only one thing in it - so when you try to access the second element in the array (with [1]) it finds that this is beyond the end of the array (out of bounds)

For example:

Stephens,Owen -> value.split(",") -> ["Stephens","Owen"] - two items in the array
Stephens Owen -> value.split(",") -> ["Stephens Owen"] - one item in the array

So - you will need to make sure that you have your names in the appropriate format to start with (family name comma given name(s) ) for this expression to work. If you can share some data and your desired outcome we may be able to suggest some approaches that might help (although managing names is always tricky because they vary so much across cultures and they can be written in so many different ways!)

Best wishes

Reply all
Reply to author
0 new messages