Click here to Skip to main content
15,884,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I work on csharp i need to get value of period and Start date from variable productData
so how to get data of start date and period from ProductData string variables using csharp
string productData = Serial No :444909812
ItemType :Electricy
User Name :ahmedsat
Start Date :2021/12/18
Period :30
End Date :2022/1/17

What I have tried:

so expected result will be
30
2021/12/18
Posted
Updated 17-Dec-21 20:00pm
v2
Comments
PIEBALDconsult 17-Dec-21 20:50pm    
Use a Regular Expression.

1 solution

Try a Regular expression:
(?:Start Date :)(?<StartDate>\d\d\d\d/\d+/\d+)(?:.+?End Date :)(?<EndDate>\d\d\d\d/\d+/\d+)
Will split out the date info from your examples, and you can then use DateTime.TryParse to convert them to DateTime objects.
 
Share this answer
 

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