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

  • SEARCH
  • Home
  • 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 9220587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:23:03+00:00 2026-06-18T03:23:03+00:00

I have this array on a foreach loop: StreamReader reader = new StreamReader(Txt_OrigemPath.Text); reader.ReadLine().Skip(1);

  • 0

I have this array on a foreach loop:

StreamReader reader = new StreamReader(Txt_OrigemPath.Text);
reader.ReadLine().Skip(1);
string conteudo = reader.ReadLine();            
string[] teste = conteudo.Split(new[] { '*' }, StringSplitOptions.RemoveEmptyEntries);

foreach (string s in teste)
{
    string oi = s;
}

The line i’m reading contains a few fields like matriculation, id, id_dependent, birthday ...
I have a CheckedListBox where the user selects wich fields he wants to select and what order he wants, according to this selection and knowing the order of each value in the array like(I know the first is matriculationthe second is id and the third is name), how could I select some of the fields, pass it’s value to some variable and order them according to the checkedlistbox’s order ? Hope I could be clear.

I tried this:

using (var reader = new StreamReader(Txt_OrigemPath.Text))
            {
                var campos = new List<Campos>();
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    string conteudo = reader.ReadLine();
                    string[] array = conteudo.Split(new[] { '*' }, StringSplitOptions.RemoveEmptyEntries);
                    var campo = new Campos
                    {
                        numero_carteira = array[0]
                    };
                    campos.Add(campo);
                }
            }

Now How may I run over the list and compare its values with those fields selected by the user from the checkedlistbox ?
Because if I instance the class again out the {} it’s values will be empty…

Person p = new Person();
string hi = p.numero_carteira;  // null.....
  • 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-18T03:23:04+00:00Added an answer on June 18, 2026 at 3:23 am

    Skip(1) will skip the first character of the string of first line returned by reader.ReadLine(). Since reader.ReadLine() by itself skips the first line, Skip(1) is completely superfluous.

    First create a class which can store your fields

    public class Person
    {
        public string Matriculation { get; set; }
        public string ID { get; set; }
        public string IDDependent { get; set; }
        public string Birthday { get; set; }
    
        public override string ToString()
        {
            return String.Format("{0} {1} ({2})", ID, Matriculation, Birthday);
        }
    }
    

    (Here I used strings for simplicity, but you could use ints and DateTimes as well, which requires some conversions.)

    Now, create a list where the persons will be stored

    var persons = new List<Person>();
    

    Add the entries to this list. Do not remove empty entries when splitting the string, because otherwise you will lose the position of your fields!

    using (var reader = new StreamReader(Txt_OrigemPath.Text)) {
        reader.ReadLine();  // Skip first line (if this is what you want to do).
        while (!reader.EndOfStream) {
            string conteudo = reader.ReadLine();
            string[] teste = conteudo.Split('*');
            var person = new Person {
                Matriculation = teste[0],
                ID = teste[1],
                IDDependent = teste[2],
                Birthday = teste[3]
            };
            persons.Add(person);
        }
    }
    

    The using statement ensures that the StreamReader is closed when finished.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this array: string[,] productData = new string[5,7]; I bind it to a
I have a foreach loop which loops through an array (simpleXML nodes). This array
I have this array loop: foreach ( $event_entrance as $event_entrance_s ) { _e($event_entrance_s,'holidayge'); echo
I have this foreach loop: foreach($aMbs as $aMemb){ $ignoreArray = array(1,3); if (!in_array($aMemb['ID'],$ignoreArray)){ $aMemberships[]
I have an associative array and while iterating through this array, using foreach loop.
So I have this foreach loop - and I want to modify the array
ok so i have this array and i need to loop through <?php foreach($classes
I have this PHP snippet: <?php $colors = array('red','green','blue'); foreach ($colors as &$item) {
I have this array {$man_data} which is structured like 10 > 'Text 8' 14
I have this code to loop the data to my website: $loop = Array();

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.