Extract only specific text from notepad

Hi all,

I need to extract one specific line of text from a notepad file that is automatically generated by SAP. The line of text (and the file name) changes each time, so I’m pretty confused by how to make this work. I’ve tried a number of things, such as screen scraping relative, converting to data table, etc., but UI Path never seems to be able to get only some of the text. I’ve attached a screenshot below. I only need the number () which follows “SUCCESS.”


Welcome to uipath community
Hope these steps could help you resolve this
— as you say it’s there in a notepad we can read it and store it a string and manipulate for the data
— use a read text file activity and pass the file path of the .txt as input and get the output with a variable of type string named out_text
— use a assign activity like this
out_value = out_text.ToString.SubString(out_text.IndexOd(“SUCCESS”)+(“SUCCESS”).Length,12).ToString.Trim

Where the output would be 0100450480

Kindly try this let know for any queries or clarification
Cheers @David_Phillips


Thank you so much for the help! I think I understand how this would work. The only problem is that I’m getting an error message that says " ‘IndexOd’ is not a member of ‘String’." Is there a small typo in the code? @Palaniyappan

1 Like

@David_Phillips that’s indexof not indexod may be at the time typing maybe it prints like that.

1 Like

Hi @David_Phillips
i have done this with regular expression attached the screen shot and the flow for your reference. hope that helps.


BlankProcess.zip (11.4 KB)

IndexOf is a method of string which gives the index position of the string passes as argument
Like this
Cheers @David_Phillips

Thank you everyone! You solved my issue perfectly.

1 Like

@David_Phillips I would highly suggest going with a regex solution instead of the IndexOf solution, as it is much more versatile. The existing IndexOf solution would not work if there were additional digits, less digits, or changes in the spaces between success and the number you want.

With Regex you could just use the Read Text File activity, save it to a string variable, then do a simple regex to pull out the information you want.expression: (?<=\bSUCCESS\s*)\d+ and make sure regex options Ignore Case is checked. You could do this with the Matches activity, or you could do it in an assign activity

This would match the word success anywhere in the text document and pull out the number immediately to the right of it. I suggest you give it a try here: http://regexstorm.net/tester and use the reference page here for any future regex help http://regexstorm.net/reference

EDIT: How the expression works: (?<=) means that it will search for the pattern you put, and grab the text immediately to the right. \b grabs a word boundary. Success is the literal word success, and \s* means it will grab 0 or more whitespaces after the word success. All together (?<=\bSUCCESS\s*) is looking for the word success by itself, followed by 0 or more white spaces. So it won’t match the word successful, and it won’t match unsuccess. After it finds success, it looks to the pattern to the right which is \d+. This means it is finding 1 or more digits. Put the whole thing together (?<=\bSUCCESS\s*)\d+ and you are finding one more digits immediately after the word success within the string you are searching

1 Like

Cheers @David_Phillips

Hi! Of course, I’d like my automation to be more versatile, but I don’t quite know how to use that action. Specifically, the Matches activity is throwing an error message that says “Compiler error encountered processing DocID.” (DocID is the variable name that I chose because the number which follows success is actually a document ID number). The message says that " ‘String’ cannot be converted to ‘System.Collections.Generic.IEnumerable (Of System.Text.RegularExpressions.Match)’ because Char is not derived from ‘Systems.Text.RegularExpresssions.Match,’ as required for the ‘Out’ generic parameter ‘T’ in ‘Interface IEnumberable(Of Out T).’

(sidenote: who makes these error messages? They’re seriously so confusing it’s ridiculous).

Thanks for your help!


Haha that is a VB.NET error not a uipath error. It is saying that DocID is a string, but the activity is expecting you to provide a different variable type (specifically, IEnumerable<Matches> type). If you use the matches activity, the result gives you an ienumerable<matches> result. So you should create a new variable of that type. I usually do this by clicking into the result property, press ctrl+k, then type in my variable name. This ensures it is the correct type. Then in a separate assign activity you should assign DocID = YourMatchesVariable(0).Value

The other way to do is to just put it all in one assign activity. Assign DocID = System.Text.RegularExpressions.Regex.Match(StringVariableYoureSearching,"(?<=\bSUCCESS\s*)\d+",System.Text.RegularExpressions.RegexOptions.IgnoreCase) Of course that is quite long. If you want to shorten it you can import the namespace System.Text.RegularExpressions into Studio, then you don’t have to type “System.Text.RegularExpressions” every time and can just type in Regex.Match(StringVariableYoureSearching,"(?<=\bSUCCESS\s*)\d+",RegexOptions.IgnoreCase)


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