0

Trying to parse text from file.txt and retrieve in text box or either in output.txt

I have text file in which there are lots of information from which I want to find line which starts with "Source:" and parse text next to it. Then exclude text from the same line of data where letters start and only keep numbers and symbols which came after word "Source:" and before the letter and words starts on the same line of data. Example data in text file: Subtype: - Bank: - Credit: - Source: 5524335312265537:|:0823:|:627:|:Krystal Flowers:|:81007:|:United States:|:Colorado:|:Pueblo East Subtype: - Bank: - Credit: - Source: 3524335312265537:|:1423:|:457:|:Brystal Dlowers:|:61007:|:United Kingdom:|:Colorado:|:Sueblo West Subtype: - Bank: - Credit: - Source: 6524335312265537:|:0323:|:827:|:Prystal Tlowers:|:41007:|:United States:|:Colorado:|:Aueblo North Output expected: 5524335312265537:|:0823:|:627 3524335312265537:|:1423:|:457 6524335312265537:|:0323:|:827

14th Dec 2021, 11:36 AM
sixehoh
2 Answers
0
File.ReadAllLines("path/to/file.txt") creates a string array. Use Linq to filter the collection: input.Where(x => x.StartsWith("Source")); Loop through the filtered collection and get the part you want. I'd use a Regex pattern. This pattern should be ok: @"\d+:\u007c:\d{4}:\u007c:\d{3}" (too lazy to count the digits of the first one...) You could skip the Linq, but if you get the filtered list first you can change the strings in place.
14th Dec 2021, 10:36 PM
Alex
Alex - avatar
0
Yes you are right with Regular Expression once we get line matching with "Source:" then we can exclude the part after "number | number | number | remove everything from here.." It would be very helpful if you can provide me the solution.
15th Dec 2021, 5:13 AM
sixehoh