Question: I have a field name where all the values are capitalized so I used title('string') to get my desired results:

```
 'OLONGAPO CITY'

```

will result to 

```
 'Olongapo City'.

```

However, there are strings such as:

```
 CITY OF MAKATI

```

I want it to appear as 

```
'City of Makati' 

```

instead of 

```
'City Of Makati' 

```

Answer: 
You could try using something like the following expression:

```
replace(title("fieldName"), 'Of', 'of')

```
If you want proper title case rules (including correct handling of a/of/the/etc), you could grab the source of Titlecase.py (See <https://muffinresearch.co.uk/titlecasepy-titlecase-in-python/> ) and insert this in a custom expression function from the "Function Editor" tab in the expression builder:

[![enter image description here](https://i.stack.imgur.com/Qsbcq.png)](https://i.stack.imgur.com/Qsbcq.png)

The code look something like:

```
@qgsfunction(args='auto', group='String')
def title_case(value1, feature, parent):
    return titlecase(value1)

```

...followed by the entire copy/pasted contents of [`https://raw.githubusercontent.com/ppannuto/python-titlecase/master/titlecase/__init__.py`](https://raw.githubusercontent.com/ppannuto/python-titlecase/master/titlecase/__init__.py)

You'll then be able to use this new `title_case` function anywhere in QGIS expressions:[![enter image description here](https://i.stack.imgur.com/j8LTf.png)](https://i.stack.imgur.com/j8LTf.png)