I have a requirement to extract 3 different key pairs from the long string and store it in a dictionary variable .
example
if my string is as below
" here are the details of your incident
Description: your issue is related to application . But please cross check ;
and your
Resolution: your application can be restarted to resolve this .Please try ;
and the root cause fix is
Root Fix: please make code level changes ;"
and my result should be
Result enumerable dictionary,
( Description:your issue is related to application . But please cross check ,
Resolution: your application can be restarted to resolve this .Please try ,
Root Fix: please make code level changes )
Please help me in this .
I have seen regex can be used to fetch any one key pair but i want to extract all three key pairs .
Hi
Hope these steps would help you resolve this
If the above string is in a string variable named str_input
Then use a assign activity like this arr_str = Split(str_input,”;”)
Where arr_str is a variable of type array of string
Now use a FOR EACH activity and pass the above variable as input
Inside the loop use a assign activity like this dic_string(Split(item.ToString,”:”)(0).Tostring.Trim) = Split(item.ToString,”:”)(1).ToString.Trim
Where dic_string is a variable of type dictionary(of string) with default value as Nee Dictionary(of string,string)
Hi @Palaniyappan
Thanks for the detailed explanation.
Could you please let me know if there is any way to remove extra words that is comming us in the key position .
example in the above string
“here are the details of your incident
Description: your issue is related to application . But please cross check ;” would be one of the item in list of strings and “here are the details of your incident
Description” would be the key of this dictionary variable .
But i need only “Description” as key .
Would this be possible from regex function to check if the key has “description/Resolution/Root fix” any of these three then consider only this as key expression .
yah we can do that
but we need a structure of string for that
will the string contains the terms like Description, Resolution and Root Fix in order
because we can get the string between Description and Resolution a value for Description
similarly string between Resolution and Root Fix as a value for key Resolution
try this regex to get those three line items
further you can split every line by colon “:” to get it in key value pair
u can also use ismatch activity with same expression to check whether those keywords exist or not
You can use regex for this as it’s much faster and stable.
If you’re very sure that all three (Description, Resolution, Root Fix) will be present, you can use the following regex to get all the three item in an array.
(?<=:).*?(?=\;)
Else if you need to get specific one, you need to use the following for each