I would like to replace one character in a string with an uppercase of the same character. Is there an elegant way to do this? Eg I have 'Donald Mcdonald' and I would like to uppercase the first 'd' in 'Mcdonald' so I end up with 'McDonald'
The string.replace function only gives the option to replace first or all. If I use the code below it obviously won't work.
if(name.containsIgnoreCase(' mc')){
integer mc = name.indexOfIgnoreCase(' mc') + 3;
name = name.replaceFirst(name.mid(mc, 1), name.mid(mc,1).toUpperCase());
}