Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8550317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:55:27+00:00 2026-06-11T13:55:27+00:00

I have an array that contains data as follows (string and time data separated

  • 0

I have an array that contains data as follows (string and time data separated by a comma):

array[0]= Channel 1, 01:05:36

array[1]= Channel 2, 02:25:36

array[2]= Group 1, 22:25:36

array[3]= Netwk, 41:40:09

array[4]= LossOf, 03:21:17

array[5]= LossOf, 01:13:28

array[6]= Channel 1, 04:25:36

array[7]= Channel 2, 00:25:36

.
.
.
array[xxx]= xxx, xxx

I would like to count all duplicates items and determine average time for each duplicate found as follows:

Item1, Channel 1, 2 occurrences, average time for each occurrence is about xx minutes

Item2, Channel 2, 2 occurrences, average time for each occurrence is about xx minutes

Item3, LossOf, 2 occurrences, average time for each occurrence is about xx minutes

The time format is hh:mm:ss

This is what I have done so far, which only gives me total times of duplicates:

public void CountDuplicates(string[] myStringArray)
{
  //count duplicates
  ArrayList list = new ArrayList();
  int  loopCnt=0;

  foreach (string item in myStringArray)
  {
    if (!String.IsNullOrEmpty(myStringArray[loopCnt]) == true)
      list.Add(item);
    loopCnt++;
  }

  loopCnt = 0;
  Dictionary<string, int> distinctItems = new Dictionary<string, int>();
  foreach (string item in list)
  {
    if (!distinctItems.ContainsKey(item))
    {
      distinctItems.Add(item, 0);
      loopCnt++;
    }
    distinctItems[item] += 1;
  }
  foreach (KeyValuePair<string, int> distinctItem in distinctItems)
  {
    txtDisplayResults.AppendText("Alarm Error: " + distinctItem.Key + ",  How many times: " + distinctItem.Value + "\r\n");
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:55:28+00:00Added an answer on June 11, 2026 at 1:55 pm

    Maybe this:

    a channel class to hold your values

    class Channel
    {
        public String Name { get; set; }
        public TimeSpan Duration { get; set; }
    }
    

    your sample data

    var array = new[]{
        "Channel 1, 01:05:36",
        "Channel 2, 02:25:36",
        "Group 1, 22:25:36",
        "Network, 41:40:09",
        "Loss of, 03:21:17",
        "Loss of, 01:13:28",
        "Channel 1, 04:25:36",
        "Channel 2, 00:25:36",
    };
    

    the query

    var channelGroups = array.Select(s =>
    {
        var tokens = s.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
        var tsTokens = tokens[1].Split(':');
        return new Channel()
        {
            Name = tokens[0],
            Duration = new TimeSpan(
                int.Parse(tsTokens[0]),  // hours
                int.Parse(tsTokens[1]),  // minutes
                int.Parse(tsTokens[2]))  // seconds
        };
    })
    .GroupBy(c => c.Name)
    .Select(g => new
    {
        Channel = g.Key,
        Count = g.Count(),
        Average = g.Average(c => c.Duration.TotalMinutes)
    });
    

    output:

    foreach(var group in channelGroups)
    {
       Console.WriteLine("Channel:[{0}] Count:[{1}] Average:[{2}]"
                        , group.Channel, group.Count, group.Average);
    }
    

    demo: http://ideone.com/6dF6s

    Channel:[Channel 1] Count:[2] Average:[165.6]
    Channel:[Channel 2] Count:[2] Average:[85.6]
    Channel:[Group 1] Count:[1] Average:[1345.6]
    Channel:[Network] Count:[1] Average:[2500.15]
    Channel:[Loss of] Count:[2] Average:[137.375]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable that contains an array from form data, seen below: $option1
I have the $user array that contains data with special characters. It seems like
Is it possible to have an array that contains two different types of data?
I have a .php file that contains array data like below: $config['setting_one'] = true;
Ok I have an associative array contains data that should be downloaded in a
I have two arrays of data that I'm trying to amalgamate. One contains actual
I have an array that contains @sign in the object. I can't access that
I have an Array that contains some elements multiple times. Now I want to
I have an array that contains the RGB colour values for each pixel in
I have an array that contains an array of arrays if that makes any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.