How do I split a string of text into multiple variables?

Hey guys
I am exploring an automation opportunity, but I have run into a problem that hope someone can help me with.

I want to save some text into a variable.

The text is as follows:
Udlandsadresse: Adr1: Roadname 10 Adr2: 123456 City Name Adr3: Country Adr4: Adr5: Fra: 01-06-2023 occurrence

What I need is to get the text between “Adr1:” and “Adr2”, and between “Adr2” and “Adr3” and so on and so on.
The text will then be saved into a varible and used to put in elsewhere.
Hope this makes sense, I am new to RPA development so bear with me :slight_smile:

Kind Regards Andreas

@Andreas_Kristensen
Welcome to the forum
we can use Regex for the extraction and if needed we can further process it. Instead of different variables we would recommend to us a collection like array,list or a dictionary
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum


grafik
Adr\d.+?(?=Adr|$)

a modified dictionary demo:

 strText
 "Udlandsadresse: Adr1: Roadname 10 Adr2: 123456 City Name Adr3: Country Adr4: Adr5: Fra: 01-06-2023 occurrence"
 strPattern
 "(Adr\d)(.+?(?=Adr|$))"
 myMatches = System.Text.RegularExpressions.Regex.Matches(strText, strPattern)
 MatchCollection(5) { [Adr1: Roadname 10 ], [Adr2: 123456 City Name ], [Adr3: Country ], [Adr4: ], [Adr5: Fra: 01-06-2023 occurrence] }
 myMatches.Cast(Of Match).TODictionary(Function (m) m.Groups(1).Value, Function (m) m.Groups(2).Value.Trim({" "c,":"c}))
 Dictionary<string, string>(5) { { "Adr1", "Roadname 10" }, { "Adr2", "123456 City Name" }, { "Adr3", "Country" }, { "Adr4", "" }, { "Adr5", "Fra: 01-06-2023 occurrence" } }