Extracting the numbers from a Log

srikanthp

New Member
Hello everyone,
I have the business requirement to extract the numbers from a log downloaded from the SAP. Once downloaded I need to extract only the numbers from the log. Then I have to add these numbers to Queue for further processing. I have the logic to extract for a single line of string using the data item.

resultString = Regex.Match(subjectString, "\d+").Value
this works only for a single data item but I need to extract the data from a collection. Please suggest a solution for this.

Thanks in advance.
 

Attachments

  • Success Log.PNG
    68.8 KB · Views: 21

Sachin_Kharmale

Active Member
Hi ,

You need to use blue prism code stage to perform regex filter operation on collection
Here i have used VB.Net code

View attachment 1558080594503.png

fig 1- Flow in Object Studio
Input to Code stage will be input collection that we have values and column name of the input collection that we want filter according to regex
View attachment 1558080698532.png
Fig-2 Input Collection which having input value to be sort

View attachment 1558080763990.png

fig 3- Code stage input

View attachment 1558080806835.png

fig 4-Code stage Output

View attachment 1558080842954.png

Fig 5- Code Stage Code

Use Following Line of Code to perform operation

Output_Collection = New DataTable ' Here we are initializing Output Collection Object
Output_Collection.Columns.Add(colname,GetType(String)) ' Create a new column same as input collection that we want to filter
Dim Number_Value As String ' Variable to store numbers from string
For Each row as DataRow in Input_Collection.Rows ' Iterating Input Collection
Dim val as String = CStr(row(colname)) ' Fetching single value from input collection
Number_Value=Regex.Match(val, "\d+").Value ' Apply regex to fetch only numbers from input string
if Number_Value <> "" ' if String does not contains number then it will empty otherwise it contains number
Output_Collection.Rows.Add(Number_Value) ' Add Numbers in output collection column on new row
End if

Next

View attachment 1558080909664.png

fig 6- When we execute code stage then we will get Numbers in output collection

Best Regards,
Sachin Kharmale
 
Top