Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How to parse the following text from a variable to extract some information like ID, QUEUE, OWNER, STATUS and LASTUPDATED?? this information is a query result from a REST API. the string "--" separate tickets in the list.

The idea is to put relevant information in a table view in a form.

The query result allways gives a header like "RT/4.0.4 200 Ok" befor relevant information.

''''''''''''''''''''''''''''''' here starts the quey result'''''''''''''''''''''''''''''
RT/4.0.4 200 Ok

id: ticket/12400
Queue: Yold
Owner: romir
Creator: geos
Subject: Hoy
Status: resolved
Priority: 3
InitialPriority: 3
FinalPriority: 0
Requestors: r@d.com
Cc:
AdminCc:
Created: Thu Jun 20 13:56:15 2013
Starts: Not set
Started: Mon Jun 24 20:19:35 2013
Due: Not set
Resolved: Mon Aug 26 14:18:35 2013
Told: Mon Jul 29 12:10:12 2013
LastUpdated: Mon Aug 26 14:18:35 2013
TimeEstimated: 0
TimeWorked: 0
TimeLeft: 0
CF.{Category}: Scripting
CF.{Environment}: Production
CF.{Type}: Development
CF.{Handover}: No
CF.{Escalated}: No

-- (this is a ticket separator)

id: ticket/12714
Queue: asdf
Owner: romir
Creator: Cageos.com
Subject: FTP Med
Status: resolved
Priority: 3
InitialPriority: 3
FinalPriority: 0
Requestors: ronR@Mmune.com
Cc:
AdminCc:
Created: Fri Jul 05 15:53:49 2013
Starts: Not set
Started: Fri Jul 05 15:57:24 2013
Due: Not set
Resolved: Fri Jul 05 16:43:08 2013
Told: Fri Jul 05 16:43:08 2013
LastUpdated: Mon Jul 29 08:21:46 2013
TimeEstimated: 0
TimeWorked: 0
TimeLeft: 0
CF.{Category}: FTP
CF.{Environment}: Production
CF.{Handover}: No
CF.{Escalated to support}: No

--
Posted

1 solution

There is no automatic way to do this: but it looks pretty simple to parse.
I'd start by splitting it into separate Tickets, by using string.Split on the "--", then processing each of the Tickets into separate lines, then each line into Key and Value pairs using the ":" character.

It's not complex stuff - but it would just depend on how you got the strings to start with.
If you use Dictionary<string, string> to hold each Ticket, then you can check for specific data with:
C#
if (ticketDict.ContainsKey("Owner"))
   {
   Console.WriteLine("Owner: {1}", ticketDict["Owner"]);
   }
and pick up the fields you are interested in.
 
Share this answer
 
Comments
Roberto A. Valomir 9-Dec-13 10:28am    
Hi, thanks for your help.

I'm new. how do you create that dictionary for this case?
OriginalGriff 9-Dec-13 10:41am    
Dictionary<string, string> lines = new Dictionary<string,string>();

[edit] stupid HTML... [/edit]

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