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 6945777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:28:46+00:00 2026-05-27T13:28:46+00:00

I have an array which contains following values: str[0]= MeterNr 29202 str[1]=- 20111101: position

  • 0

I have an array which contains following values:

str[0]= "MeterNr 29202"
str[1]="- 20111101: position 61699 (Previous calculation) "
str[2]="- 20111201: position 68590 (Calculation) consumption 6891 kWh"
str[3]="- 20111101: position 75019 (Previous calculation) "
str[4]="MeterNr 50273"
str[5]="- 20111101: position 18103 (Previous reading) "
str[6]="- 20111201: position 19072 (Calculation) consumption 969 kWh "

I want to split the rows in logical order so that I can store them in following Reading class. I have problems with spliting the values. Everything in brackets () is ItemDescription.

I will be thankful for the quick answer.

public class Reading
{
    public string MeterNr { get; set; }

    public string ItemDescription { get; set; }

    public string Date { get; set; }

    public string Position { get; set; }

    public string Consumption { get; set; }
}
  • 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-05-27T13:28:47+00:00Added an answer on May 27, 2026 at 1:28 pm

    I would just use a for loop and string indexes etc, but then I am a bit simple like that! Not sure of your data (i.e. if things might be missing) but this would work on the data you have posted…

    var readings = new List<Reading>();
    int meterNrLength = "MeterNr".Length;
    int positionLength = "position".Length;
    int consumptionLength = "consumption".Length;
    string meterNr = null;
    
    foreach(var s in str)
    {
        int meterNrIndex = s.IndexOf("MeterNr",
                                     StringComparison.OrdinalIgnoreCase);
    
        if (meterNrIndex != -1)
        {
            meterNr = s.Substring(meterNrIndex + meterNrLength).Trim();
            continue;
        }
    
        var reading = new Reading {MeterNr = meterNr};
    
        string rest = s.Substring(0, s.IndexOf(':'));
        reading.Date = rest.Substring(1).Trim();
    
        rest = s.Substring(s.IndexOf("position") + positionLength);
    
        int bracketIndex = rest.IndexOf('(');
    
        reading.Position = rest.Substring(0, bracketIndex).Trim();
    
        rest = rest.Substring(bracketIndex + 1);
    
        reading.ItemDescription = rest.Substring(0, rest.IndexOf(")"));
    
        int consumptionIndex = rest.IndexOf("consumption",
                                            StringComparison.OrdinalIgnoreCase);
    
        if (consumptionIndex != -1)
        {
            reading.Consumption = rest.Substring(consumptionIndex + consumptionLength).Trim();
        }
    
        readings.Add(reading);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following view model which contains an array of elements function ReservationsViewModel()
I have variable call items having array of items which contains following value [[#<Item
I have an array which contains duplicate values. I want to sort the array
I have an array which contains another array Would I notate it this way?
I have an array which contains around 50-200 hyperlinks. How can I pass this
Am I missing something in the Array documentation? I have an array which contains
I have an array DetailsArray in VB.NET which contains the result of a LINQ
I have a plist which contains an array of NSDictionary 's which represent a
I have an array that contains a list of vertices which I copy to
I have an NSArray which contains Person objects. This person object contains the following;

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.