Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

Formatting String from Data

I have data like this:
    Name	Update
    CC		12/31/2012
    CS		12/31/2012
    CI		04/30/2013
    CR		04/30/2013

Open in new window

I need this output:
    Annual CC/CS Update: 12/31/2012
    Annual CI/CR Update: 04/30/2013

Open in new window

If my data is like this, however:
    Name	Update
    CC		12/31/2012
    CI		04/30/2013

Open in new window

I need this output:
    Annual CC Update: 12/31/2012
    Annual CI Update: 04/30/2013

Open in new window

Not sure how to accomplish this task.
0
Eddie Shipman
Asked:
Eddie Shipman
  • 2
1 Solution
 
p_davisCommented:
Dictionary<DateTime, List<String>> dictionary = new Dictionary<DateTime , String >();

foreach(yourObject yo in yourDataList)
{
                 if(dictionary.ContainsKey(yo.Update))
                 {
                           dictionary[yo.Update].Add(yo.Name);
                  }
                  else
                 {
                           dictionary.Add(yo.Date, new List<String>());
                            dictionary[yo.Update].Add(yo.Name);

                  }
           Dictrionary<DateTime, String>.Enumerator enumer = dictionary.GetEnumerator();

              while(enumer.MoveNext())
              {
                              String yourOutPut = String.Format(Annual {0}  Update: {1}, String.Join("/", enumer.Current.Value.ToArray(), enumer.Current.Key);
               }
}
0
 
p_davisCommented:
there might be a few typos...had to do it outside of an ide.
0
 
Eddie ShipmanAll-around developerAuthor Commented:
Since I already had it as a dictionary for another use, I decided to use LINQ on the data object. Thanks, anyway.

Here's the source I actually used:
<div class="span6">
	<p>
	@{
		var designationsByDate = AllianceDesignations.GroupBy(designation => designation.UpdateDue).OrderBy(values => values.Key);
		IEnumerable<string> rowsOfData = designationsByDate.Select(designationByDate =>
		{
			string annual = designationByDate.Aggregate(string.Empty, (acc, designation) => acc + "/" + designation.Name);
			return string.Format("Annual {0} Update {1}<br />", annual.Substring(1), designationByDate.Key.ToShortDateString());
		});
	}
	@foreach (var Row in rowsOfData)
	{
		if(!Row.Contains("0001")) {
			@Html.Raw(Row);
		} else {
			@Html.Raw("&nbsp;");
		}
	}
	</p>
</div>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now