Well, this is my alternative suggestion, not the answer to your question.
The string manipulation operation is always very important and tedious, and for a long time it does not work perfectly.
I have a very good alternative that you would prefer. Instead of having one line address, it is better to split into another part.
eg. Street1 street # 2 city state country
Now in the database you can create an XML data type and save all the above field in a field in XML format, for example
<Address> <street1>data1</street1> <street2>data2</street2> <city>data3</city> <state>data4</state> <country>data5</country> </Address>
The advantage of this:
1. Now you can flexibly insert and retrieve data, if the user does not want to enter any field, or you do not want to display any field, then this is the best way to do it.
2.It will give you good performance, but because XML Parsing is faster than string manipulation.
3.XML returns more precision than a string operation.
source share