Copy text and seperate

Hello, my robot copies the entire text:

  • surname:
  • name:
  • address:
  • phone number:

I would like the value after “:” to be copied to variables. Separate surname, separate name, etc.
When I did: “split” after “:”, it also copied the second line.
I would like each line to be separate.
How can I do this?

Hi @sullivanne ,

You can do this as below,

Assign → TextToProcess = "surname: Doe" + vbCrLf + "name: John" + vbCrLf + "address: 123 Main St" + vbCrLf + "phone number: 555-1234"

Assign → Lines = TextToProcess.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

For Each → item In Lines
    Assign → LineParts = item.Split(":"c)
    Switch → LineParts(0).Trim.ToLower
        Case → "surname"
            Assign → Surname = LineParts(1).Trim
        Case → "name"
            Assign → Name = LineParts(1).Trim
        Case → "address"
            Assign → Address = LineParts(1).Trim
        Case → "phone number"
            Assign → PhoneNumber = LineParts(1).Trim
    End Switch
End For Each

Hope it helps you

Vinit Mhatre

Hi @sullivanne

By using regex you can store it into different variables




Sequence13.xaml (11.2 KB)


1 Like

Hi @sullivanne

Assign -> textData = "Surname: Smith
                      Name: John
                      Address: 123 Main St
                      Phone number: 555-1234"

Assign -> keyValuePairs = System.Text.RegularExpressions.Regex.Matches(textData, "(?<key>[^:\r\n]+):\s*(?<value>[^\r\n]+)")

Assign -> surname = keyValuePairs(0).Groups("value").Value.Trim()
WriteLine -> surname

Assign -> name = keyValuePairs(1).Groups("value").Value.Trim()
WriteLine -> name

Assign -> address = keyValuePairs(2).Groups("value").Value.Trim()
WriteLine -> address

Assign -> phoneNumber = keyValuePairs(3).Groups("value").Value.Trim()
WriteLine -> phoneNumber

Note: textData, surname, name, address, phoneNumber are of DataType System.String
keyValuePairs is of DataType IEnumerable(System.Text.RegularExpressions.Match)


Sequence32.xaml (9.8 KB)


Hello, thank You, but I have error:

HI @sullivanne

Can you please confirm the data type of the variable keyValue?


I have these types of variables: :slight_smile:

Hi @sullivanne

Can you send me the screenshot of the variable panel?


Hi @sullivanne

Check below
MicrosoftTeams-image (144.2 KB)


Have a look here at a generic approach retruning a dictionary

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