How can we get each value in seperate variable from below text string-
Patient Info:Cxxxx, Axxx
SSN: xxxxxxx
DOB: May 24 1987 12:00AM
Addr.: 1xxxx Kxxxxxx St.
Rxxxxx, CX xxxxx
Phone: (XXX) XXX-XXXX
DoI: 1/20/2019
Claim: AXXX-0XXXX
How can we get each value in seperate variable from below text string-
Patient Info:Cxxxx, Axxx
SSN: xxxxxxx
DOB: May 24 1987 12:00AM
Addr.: 1xxxx Kxxxxxx St.
Rxxxxx, CX xxxxx
Phone: (XXX) XXX-XXXX
DoI: 1/20/2019
Claim: AXXX-0XXXX
Declare a string variable in variable panel and then use an assign activity to assign that variable to the given string.
Patient Info:Cxxxx, Axxx
SSN: xxxxxxx
DOB: May 24 1987 12:00AM
Addr.: 1xxxx Kxxxxxx St.
Rxxxxx, CX xxxxx
Phone: (XXX) XXX-XXXX
DoI: 1/20/2019
Claim: AXXX-0XXXX
This information is in one string or one text
@Rrupam13
myString.Split(Environment.NewLine.ToCharArray,StringSplitOptions.RemoveEmptyEntries)
will give you an array of strings with each array item being a single line of the original string. Then, you can loop through that array with a For Each and process each item. You could split each line by :
to separate the key from the value or you could could explicitly check for text like “Patient Info:”, etc.
I would use string.split by newline (option for RemoveEmptyEntries = true), then store it into a dictionary (of string, string) where the key is the information to the left of the colon, and the value is the information to the right of the colon.
The only issue with the above solution is that the address does not follow the same pattern as everything else. So that’ll be the first thing we fix.
I’ll assume your full string here is saved to a string variable called FullText. I am also assuming this format will remain exactly the same for all strings you will be receiving. Please import namespace System.Text.RegularExpressions into the ‘imports’ tab of the variable/argument/imports pane.
1. Assign RegexExpr = "(?<=Addr.:.+(\r\n){2}).*" // This is a string variable
2. Assign Addr2Text = "Addr2.: " + Regex.Match(FullText,RegexExpr) // This is a string variable
3. Assign FullText = Regex.Replace(FullText,Addr2Text,RegexExpr)
Now your FullText string will look like this:
Patient Info:Cxxxx, Axxx
SSN: xxxxxxx
DOB: May 24 1987 12:00AM
Addr.: 1xxxx Kxxxxxx St.
Addr2.: Rxxxxx, CX xxxxx
Phone: (XXX) XXX-XXXX
DoI: 1/20/2019
Claim: AXXX-0XXXX
Now everything is consistent and you can put it in your dictionary.
1. Assign MyDictionary = New Dictionary(of string, string) // This is a dictionary(string, string) variable
2. Assign FullText = Regex.Replace(FulText, “^\s+$[\r\n]*”, “”, RegexOptions.Multiline) // This removes the empty lines from the FullText string
3. For each str in FullText.Split(":",StringSplitOptions.RemoveEmptyEntries) // This is a for each activity. Change the TypeArgument to string
3a. Add to Dictionary. Dictionary: MyDictionary ; Key: str(0) ; Value: str(1) // This activity is part of the Microsoft.Activities package. You'll need to download through the manage package (ctrl+p) if you don't have it already
4. Now when you want to access it elsewhere in your workflow, you can access it by saying MyDictionary(key) and it will output the value as a string. For example MyDictionary("DOB") would give you the string "May 24 1987 12:00AM"