Extracting values from strings

I have the string below I want to remove client ID Client Name and Client Country then store the value in three separate strings. please note that the current values will not always be the same. E.G. client country could be England.
“Client ID: AD3875
Client Name: Villacorta
Client Country: Italy”

Hello @duaine.b, try this:

Dim inputText As String = “Client ID: AD3875
Client Name: Villacorta
Client Country: Italy”

Dim lines As String() = inputText.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)

Dim clientIdLine As String = lines.FirstOrDefault(Function(line) line.Contains(“Client ID”))
Dim clientNameLine As String = lines.FirstOrDefault(Function(line) line.Contains(“Client Name”))
Dim clientCountryLine As String = lines.FirstOrDefault(Function(line) line.Contains(“Client Country”))

Dim clientId As String = If(clientIdLine IsNot Nothing, clientIdLine.Replace(“Client ID:”, “”).Trim(), “”)
Dim clientName As String = If(clientNameLine IsNot Nothing, clientNameLine.Replace(“Client Name:”, “”).Trim(), “”)
Dim clientCountry As String = If(clientCountryLine IsNot Nothing, clientCountryLine.Replace(“Client Country:”, “”).Trim(), “”)

’ Now you have the extracted values in the clientId, clientName, and clientCountry variables

Cheers! :slight_smile:


[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum



Hi @duaine.b

you can use

System.Text.RegularExpressions.Regex.Matches(inputstr,“(?<=: ).*”)

it gives the output as collection

1 Like

Also have a look at this for a generic dictionary creation apprioach:

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