How to separate a Dictionary of str wherein Keys are to be split based on (-)

more details - Dictionary (of String, String)
Dictionary =Key(Form Number) Value(Form Title & Notes)
A111-B111 xyz…
A111-B111 xyz…
A111-B111 xyz…
A111-B111 xyz…

I need to split Form number And get A111 only.

Add Ref: I have converted a dt to Dic
Datatable.AsEnumerable.ToDictionary(Function(x)x.Item(“Form Number”).ToString,Function(x)x.Item(“Form Title & Notes”).ToString)

to Dic(str,str)

@sudharsan you can go with for each and do the split(“-”) then add to new dictionary

Hi @sudharsan

You can use regex to do so.

If you’re not sure how many characters are before your “-”, you can use this regex:

\S*(?=-)

or this:

[A-z0-9]*(?=-)

If you are sure, we can be a bit more precise (let’s say you have 4 characters as in your given example) and use this regex:

\S{4}(?=-)

or this:

[A-z0-9]{4}(?=-)

Please let me know if you’re unsure of how to use the regex in it’s entirety.
You can always use this website if you want to play around with regex :slight_smile:
regex101: build, test, and debug regex

HI @sudharsan

Try this

Datatable.AsEnumerable.ToDictionary(Function(x) System.Text.RegularExpressions.Regex.Match(x.Item(“Form Number”).ToString,".*(?=\-)").Tostring,Function(x)x.Item(“Form Title & Notes”).ToString)

Can you share your Sample Output?

Regards
Sudharsan

Hi, thanks but i have never used regex ,so I don’t know how this even goes into the work flow…

Regards,

There are two basic ways, through the “Matches” activity or through an assign with code, as @Sudharsan_Ka has shown above.

You can read a bit on regex here:
How to Extract Data With RegEx in UiPath – andersjensenorg

Ok, Great will look into it.

Thank you

Thanks a lot Sudharsan, It worked.

Regards,
Sudharsan

That’s Great @sudharsan

Kindly close this topic , So that it will be helpful for others

Happy Automation!

Regards
Sudharsan

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