The filtered string must start with “T.C. SAKARYA” and end with next “T.C.”
For the schematic when string contains “blablablablablaT.C. Sakarya lablablablabT.C.”
It will have to extract “TC. Sakarya lablablablab”
And I’m holding the “SAKARYA” in a variable. I think I should use regex but don’t have any experience with it. I uploaded the txt file as well.
document.txt (8.3 KB)
Welcome to the Community
Please try this
System.Text.RegularExpressions.Regex.Matches("YourString","T\.C\. SAKARYA.*T\.C\.")
cheers
Let me know your requirements -
string must start with “T.C. SAKARYA” and end with next “T.C.”
Is the names are constant or Anything else
So that I can help you on this
There are many “T.C” string in the text file. The one I want it included in my filtered string must start with “T.C. SAKARYA” and I’m holding “SAKARYA” in a variable. All other string variables aren’t important. But the string must end with the next “T.C.”. So It won’t include two “T.C.” in the filtered final string. Could you check the file please
How do I output this value if I assign it to a variable. It returns “System.Text.RegularExpressions.MatchCollection”. I tried “.toString” method.
Thank you
You can loop the value in a loop to get each matched value
or to get first value use Matchcoll(0).Value
Matchcol is the Matchcollection variable .replace it according to your variable
cheers
Try this it will work
System.Text.RegularExpressions.Regex.Matches(“YourString”,“T.C. SAKARYA.*T.C.”)
Store in variable & use that in for each it will work
It gives me this error, I assign my string to “mystring”.
If I add “.ToString”, For Each loop doesn’t give me the desired value.
My bad . This is the regex to use
System.Text.RegularExpressions.Regex.Matches("YourString","T\.C\. SAKARYA.*T\.C\.")
And your matchcol variable should be of type Matchcollection
Adding .ToString will not work . Change the variable type as shown above
cheers
It does return the next “T.C.”, but It can be dealt with substring methods thank you
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.