Extract only specific part from a string


#1

i have a string containing address and i want to pick only state/province from it which will always be two alphabets.please suggest.
Example:
house no.1,Abc street
Berlin,ON, L65X1W

I have to pick only ‘ON’ from this whole address string.
Please suggest


#2

Hi @somya177
You can use the below methods

  1. regex
  2. substring
    3 split method you can check each value

Regards,
Arivu :slight_smile:


#3

can you give an example?


#4

Use regex pattern [A-Z]{2}

Regards,
Arivu :slight_smile:


#5

how we will display the result of it?
Like i just want ON from the whole string to be displayed.


#6

Split the string on new line, then on comma character and get the second element


#7

can u please share the workflow sample?


#8

Sequence.xaml (6.3 KB)


#9

Hi,

I am getting below error
Assign: Index was outside the bounds of the array.


#10

Hi,

I am getting below error.:

Source: Assign

Message: Index was outside the bounds of the array.

Exception Type: System.IndexOutOfRangeException


#11

No error here… Did you run my sample or it gives an error after adapting in your flow?

image


#12

in my flow,there is space and not comma.
so i replaced comma with space IN SPLIT function in order to make my workflow work.
it is: BERLIN ON L65X1W


#13

Great, if it’s working


#14

no…its giving the previous error


#15

Then post the exact input file/text here…


#16

this is the exact input;

1-7200 KENILWORTHROAD RD
BRAMPTON ON L6T0C1

i just want to extract ON from this.


#17

Should work as I have written it, replacing comma with space. The difference might be the newline character. I think the error is on the first split. Check there.


#18

should i should not do first step?


#19

first split should be done on new line?


#20

is there any way to use it using substring?