Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to parse specific line of data from text document after prefix text "Source:" and then exclude text where letter/words starts on the same line, then retrieve only "Numbers including only Vertical line/Bar Symbol" in textbox or either in output.txt file.

Example data in text file:
Credit: -
Source: 5524335312265537:|:0823:|:627:|:Allen E Prieto:|:81007:|:United States:|:Colorado:|:Pueblo West:|:1656 W Alvarado dr:|:9109153030:|:xyz@gmail.com

Credit: -
Source: 5524331591654699:|:1123:|:617:|:Krystal Flowers:|:33179:|:United States:|:Florida:|:Miami:|:655 Ives Dairy Rd:|:5056994899:|:abc@gmail.com

Credit:
Source: 4118230087730234|09|25|430|Kera Tasey|13705 Neptune Lane|New Concord|Ohio State|43762|PE|7405863997


Output Expected:
5524335312265537|0823|627
5524331591654699|1123|617
4118230087730234|09|25|430


What I have tried:

Reference Code I am trying to implement in my program:
https://stackoverflow.com/questions/30532736/how-to-get-datas-from-text-file-in-c-sharp

C#
using (StreamReader sr = File.OpenText(filename))
{
    while ((s = sr.ReadLine()) != null)
    {
        if (s.Contains("Source:"))
        {
            s = s.Replace("Source:", "");
            foreach (string str)
            {
                string value = string[] str1[1].Replace(":", string.Empty).Replace(""", string.Empty);
            }
        }
    }
}
Posted
Updated 14-Dec-21 6:34am
v11
Comments
PIEBALDconsult 14-Dec-21 8:38am    
I'd use a Regular Expression.
[no name] 14-Dec-21 10:41am    
give an example if you have solution
BillWoodruff 14-Dec-21 15:10pm    
Look carefully at the difference in structure between the first two entries, and the third: variations like that make parsing much more complex,

Is there any way you re-structure the data to avoid inconsistency in format ?

1 solution

Quote:
It would be very helpful if anyone could write the program in c# or java.

That isn't how it works.
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
[no name] 14-Dec-21 8:04am    
just updated post have a look

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900