You could just do regexreplace - something along the lines of this ( assuming your data starts just below the header in column B:
=ARRAYFORMULA(REGEXREPLACE(B2:B,"U of San Diego|University of San Diego","USD"))
You could also place your list of variations anywhere (pretend column A), and just join them with the pipe symbol like this which effectively creates your regex out of a list you can easily keep adding to:
=ARRAYFORMULA(REGEXREPLACE(B2:B,JOIN("|",A2:A),"USD"))
I forgot to mention - because your input is user generated - I suggest making your regex all lowercase, and referencing the data to be switched also in lowercase - thus avoiding any issues with case sensitivity, like this:
=ARRAYFORMULA(REGEXREPLACE(lower(B2:B),JOIN("|",indirect("A2:A"&counta(A:A))),"USD"))
Here is an Apps Script for this purpose. The function titleCaseRange
title-cases the content of the currently selected range (which may be a single cell or a rectangular block). The function titleCase
is used by it to handle an individual string.
function titleCaseRange() {
var range = SpreadsheetApp.getActiveRange();
var values = range.getValues();
if (values.map) {
range.setValues(values.map(function(row) {
return row.map(titleCase);
}));
}
else {
range.setValue(titleCase(values));
}
}
function titleCase(str) {
return str.toString().split(/\b/).map(function(word) {
return word ? word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() : '';
}).join('');
}
The logic can be adapted to other situations, e.g., you may want to have a custom function like =title(A3:B8)
that converts a range to title case (but no longer in the same place as the data originally was). This would use the same titleCase
above, but the rest would be different:
function title(values) {
if (values.map) {
return values.map(function(row) {
return row.map(titleCase);
});
}
else {
return titleCase(values);
}
}
Best Answer
Welp found it. Read the docs.
The formulas are
=upper()
=lower()
=proper()
There is also this answer if you need something fancy because the cells will be overwritten. Convert all text to UPPERCASE in a Google Spreadsheet
But the formulas work great.