Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Native Formatting User Address String

I’m trying to format an address string in React Native.

The address string data given is 123 STREET, 123 CITY, PROVINCE 123

and I want to show only PROVINCE 123

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What should I do.

Any help will be appreciated

>Solution :

if the address format is consistent, you could do this:

const address = "123 STREET, 123 CITY, PROVINCE 123"
const province = address.split(', ')[2]

the split function .split(', ') turns the string into an array of substrings and use ', ' as the separator, which return an array like this

["123 STREET","123 CITY","PROVINCE 123"]

then just access the index of the province, you could do this if only the format is consistent (street and city must be provided or at least an empty string just to keep the format street-name, city-name, province-name)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading