Need help to string manipulate a single address into multiple lines

Hello, I’ve been trying multiple ways to properly read a dummy invoice.
My goal was to get 4 addresses/bank details.

I managed to use regex and seperate the addresses from the pdf extract.
These addresses are in proper format (Maintains lines for Company Name, City in next line, Country in 3rd line.) and usually doesnt cross 4 lines. (I’m using count array to post them to excel rows serially.

My problem is with the banking details. These are usually in one long sentence, and often surrounded by other texts. I’ve seperated the static texts and got the whole bank address but if it was static, this could have been very easy.
The invoices are supposed to change these details, so I needed to get a dynamic extraction condition to get these banking details in 3-4 seperate lines.

My aim is to have the banking details in 3-4 lines because my output invoice will look like that.
So far I’ve used SWIFT as a delimiter to seperate that part. However I can’t figure how to seperate the street address and city/state/country name in another row.

I’ve thought of using the commas as seperators, but there can be too many commas in some address and I’m not looking for a address output that takes 7 rows.

My sample sentence would be →

HELLENIC BANK 173 Athalassa Ave., 2025 Strovolos, Nicosia, Cyprus. Swift: HEBACY2N

and target is →

HELLENIC BANK
173 Athalassa Ave., 2025 Strovolos,
Nicosia, Cyprus
Swift: HEBACY2N

Please note, I can’t keep any of these words in my code, as these are to be dynamic, so it can work with most banks, the only fixed part would be the Swift code.

Utmost thanks and appreciate whoever drags me out of this mess. I’m very new to UiPath, same for substrings and regex.

Hi @fazewalker

will splitting on comma with count work?

like say you string is

str = "HELLENIC BANK 173 Athalassa Ave., 2025 Strovolos, Nicosia, Cyprus."

will be your first bank details
str.Split(","c)(0)

Last is Country
Str.SPlit(","c)(Str.SPlit(","c).Count-1)

Last but two is your state
Str.SPlit(","c)(Str.SPlit(","c).Count-2)

Remaining goes into street address as one by using a replace activity …you already have which are separated do a replace of them and remaining is the required street details

Or

If you have a list then we have to create a look up on the list

cheers

Hi,

How about the following step?

Insert linebreak at ahead of the first number.

yourString = System.Text.RegularExpressions.Regex.Replace(yourString,"(?<=^\D+)\s+(?=\d)",vbcrlf)

Insert linebreak at behind the last 2nd comma.

yourString = System.Text.RegularExpressions.Regex.Replace(yourString,"(?<=,)\s+(?=[^,]+,[^,]+$)",vbcrlf)

Insert linbreak at ahead of Switft:

yourString = System.Text.RegularExpressions.Regex.Replace(yourString,"\s+(?=Swift:)",vbcrlf)

Sequence2.xaml (5.9 KB)

Regards,

Hi @Anil_G, sorry for the late response, I was away on a weekend trip.

I’ve tried your method and it seems there are some limitations when I used multiple bank addresses. And somehow I could not bring out Cyprus out of it (After I brought out Nicosia). That’s probably my incapability, please shed some light on it whenever you can so I can remember.

Hi @fazewalker

If there are multiple bank addresses thwn first spearate them into different and loop theough each of the address.

And for the part of getting cyprus would be to get the last array item when split on comma(,) unless there is a change in format of how the string looks

Cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.