Capitalization of drug name

In my data set I use a Drug name (Brand) to generate a series of names that are not checked in any way. I wanted to make them name case but couldn’t find a method/function to do it. For now I am using this.capitalize.

It works fine until I introduce blanks and then I get the usual “cannot access blank…” error. I have tried a number of approaches such as:
if this == ‘’ then ‘’ else this.capitalize end
if this.nil then ‘’ else this.capitalize end
(this.capitalize || ‘’)

None works - what does the team think?

You could use

(this || '').capitalize

or

if this.nil? then '' else this.capitalize end

(note the “?” at the end of nil above)

That works - a slight quirk the blank field generated appears as ,"", in the CSV file; whereas blanks usually appear as , if that’s clear.

The ‘?’ is a good hint

Ah, in that case you should use:

if this.nil? then nil else this.capitalize end