How to find result out of a string

I have used OCR test result from an captcha image and stored the output as a string.

Now I need to extract the numerics and find the solution. Can someone help me how to achieve this?

I have attached a sample of question, here I need to find the middle number.
This question also can be find the 1st number, find the last number or find the total of those, or sometimes largest number or smallest number etc.

image

@Ranjit_Nayak1

You have to use switch case statement and accordingly proceed with the process

For getting numbers you can use split activity

Arr = Str.split({"?",","},StringSplitOptions.None)

In this array are(1),arr(2),arr(3) are the numbers

And use str.Contains to check if it says middle,end ,largest for each string that you might find and give th logic in the switch case accordingly

Cheers

1 Like

Hi @Ranjit_Nayak1 ,

If you do have a definite list of Questions that is already known to appear, We could prepare the Logic for it by using the Switch Activity but if the question can be of any sorts, we would not be able to do it in a rule based manner.

If i can get the solution for this, can use the same method for other questions. the question i have captured as a string by ocr. will try this.

1 Like

Thanks for this solution, could you please share a screenshot how to apply switch case for this.

Lets say i have stored the whole line in a string Str.

Hi @Ranjit_Nayak1 , have you tried extracting the value via regular expressions? you can use “[0-9]” as the pattern to extract only the numbers from the text.

The result would be a collection of matches which you can iterate through.

@Ranjit_Nayak1

It would be better to use Else if rather than switch…As there are extra text values as well.It looks like this

And also for extracting number you can either use split or if the separators are changing then use regex \d+ which would also work as stated by @Balaji_Murugan

cheers

Hi,

Try this workflow,
1.Use get ocr text activity to get a output string.
2.Use regular expression to get a list of numbers

use this expression: `

system.Text.RegularExpressions.Regex.Matches(Ocrtext,“(\d)+”)

  1. Add your list of condition as a string and iterate through for each activity.
    4.Use switch activity and add the cases based on the condition you have.

image
image

thanks!

1 Like

I have used flow decision and taken output as captcharesult for different captcha. I used just the below and was able to find smallest number, need to use the same process for others aswell. If we can simplify the below, please suggest.

Hi Guys,

I somehow could use Arr to store the values and I am able to extract max value, min value etc. result= arr.Min or arr.Max

Can someone suggest how to use Sum() for this, its expecting int value to use Sum.

@Ranjit_Nayak1

Arr.sum would give the sum ideally

Or

Cint(Arr.sum(function(x) cdbl(x)))

Cheers

1 Like

Using regular expression, its giving error only for that activity line- its not compatible. So I have used alternate solution.

Hello All,

I tried all above solutions couldn’t achieve, found my own solution for this as mentioned below, hope it helps others for such usecase if incase.

No need to use any loop here also, its so easy.

arr = String1.Split({“,”},StringSplitOptions.None) //this is to split with delimiter
arrInt= Array.ConvertAll(arr, function(str) cint(str.trim)) //this is to convert str array to int array for calculation
.
.

Then I can use as below:
addition= arrInt.Sum()
largestNo= arrInt.Max()
smallestNo= arrInt.Min()
firstNo= arrInt.First()
lastNo= arrInt.Last()
subtraction= arrInt.max()-arrInt.min()
middleNo= arrInt(1)

so on…

1 Like

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