I have a keyword in a notepad file which is extracted as a variable. Suppose in the below document, I extracted the keyword “government”, and I save it into a string variable.
This is to match 0 to 100 characters before and after ‘government’ keyword
This will give you a matchcollection which can be accessed usign for loop and changing type argument to Match, Then currentitem.Value will give each matched value if multiple matches are found
I have one more doubt,
Suppose in the example that i have given above, I want to take the keyword “prosper” which is before a full stop in the second line. so when i run the bot, i’m not able to get the 100 characters after the full stop.
So i want to add a sentence “end of line” after the full stop (if the keyword is coming before a full stop).
What I meant is, in the above example, suppose we have the keyword “labor”, There is a full stop (.) after the keyword and there is no more text after the keyword, which means it is the end of the sentence, and it won’t take the 100 characters after the keyword, since there is no more character.
So, my question is like how we can add some word like “/end of line/” at the end of the output if there is no more characters after the keyword, to let the user know that it is end of the sentence.
Possibly within the previous expression that you have given me.
So if I understand correctly …After identifying say there are less than 100 characters identified because of sentence being lesser than 100 characters then you want to add a word as end of line?
So this is applicable say even if you identify 99 characters you want to write end of line after that?
If that is the case then after extracting the data using provided regex
use a split and do count…if count is less than 100 append end of line
1.Extract regex amd say string is stored in str
2. in If condition str.tolower.Split(“government”)(1).count < 100
3. If yes str = str + “End of line” .
In our scenario we have to print 100 characters before and 100 characters after the keyword.
But let’s suppose the keyword is the last word in the sentence and in the txt file. Like the keyword “labor” in this screenshot below.
So, it will print only the previous 100 characters and not the 100 characters after the keyword since it is the end of sentence in the text file and there is no characters to print after the keyword.
So, i want to print a sentence “End of line” after the keyword “labor”, if it is the last word of txt file.
1.Extract regex and say string is stored in str
str= System.Text.RegularExpressions.Regex.Matches(“Your string”,“(\s|.){0,100}” + Variable + “(\s|.){0,100}”)(0).Value
2. in If condition str.tolower.Split(variable)(1).count < 100
3. If yes str = str + “End of line” .
Of if condition is not count and you want to check only full stop in step 2 use below
str.tolower.Split(variable)(1).Trim.Equals(“.”)