If you find the VBA and Regex a little intimidating there are the Replace and Match activities in your activities panel which help to guide you a little more.
Here I have first split the input string by newline into an array and then grabbed the third line to use as my input. By then using the Replace Activity you can identify both the house number and street name to output to individual variables.
I have a String like this
“Enschede
7514 CB
H.B. Blijdensteinlaan 18
Netherlands”
The only things I need in this string are: H.B. Blijdensteinlaan 18 so this is line 3 (always line 3) now i want to put everything till the number in one variable and the number in one variable.
So i need this:
Variable 1: Streetname: “H.B. Blijdensteinlaan”
Variable 2: Housenumber: “18”
For this example, I loaded it from a text file, but you can just as easy assign it the value from your row.
And you end up with two new String variables, one for the Street name: H.B. Blijdensteinlaan
And one for the number: 18
The Regex can also be a bit improved for the street number, depending on your situation. As it is: \d+, it will not detect house numbers that contain a letter, i.e. 18a. In this case, it would only detect the digits and skip the ‘a’.
In the process, I first split the string into multiple lines based on a new line character, which allows me to focus on the 3rd row every time. Then, I run some basic Regex to assign street name and street number to separate variables.
I think it’s a little different. My String is read from Excel so it’s an Generic Value. When i put this in a String and then try to split like this: adres.Split({System.Environment.NewLine}, System.StringSplitOptions.RemoveEmptyEntries)(2) I
Its telling me that the index was outside the bounds of the array.
Your solution is good! The only thing is that Your inputstring is assigned by yourself. My assignedstring is an GenericValue from Excel. When i implement your solution it tells me that the index was outside the bounds of the array. Its telling me that with this adres.Split({System.Environment.NewLine}, System.StringSplitOptions.RemoveEmptyEntries)(2)
In fact, I’ve just tested this above scenario after converting my input variable to a Generic type variable and it simply worked as it should.
Please debug your process a bit. To do so, add a Write Line activity with your Generic variable and post a screenshot from your Output pane. My bet is that your input variable is a bit shorter and the Split method does not return an element with an index of 2 after its called (thus the error you are getting).
I would try checking other indexes in your Split method, try these first:
adres.ToString.Split({System.Environment.NewLine}, system.StringSplitOptions.RemoveEmptyEntries)(0)
The second two are Integers, you can’t assign them to a String. That’s what that error message means.
You could log them to see the difference in array length between splitting and splitting while removing empty entries.
If adres.ToString.Split({System.Environment.NewLine})(0) gives you “Enschede” then adres.ToString.Split({System.Environment.NewLine})(2) should give you the line you need. Then you can use the regex that @ronanpeter and @loginerror provided above to separate the pieces you need.
Yeah i know but the problem is when i change the (0) to (2) so i should get the line i need. It gives me an error index was outside the bounds of the array