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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:37:14+00:00 2026-05-17T19:37:14+00:00

I am getting a list of file names using the following code: //Set up

  • 0

I am getting a list of file names using the following code:

        //Set up Datatable
        dtUpgradeFileInfo.Columns.Add("BaseFW");
        dtUpgradeFileInfo.Columns.Add("ActiveFW");
        dtUpgradeFileInfo.Columns.Add("UpgradeFW");
        dtUpgradeFileInfo.Columns.Add("FileName");

        //Gets Upgrade information and upgrade Files from Upgrade Folder
        DirectoryInfo di = new DirectoryInfo(g_strAppPath + "\\Update Files");
        FileInfo[] rgFiles = di.GetFiles("*.txt");
        foreach (FileInfo fi in rgFiles)
        {
            test1 = fi.Name.ToString();


        }

All file names will be in the form BXXXX_AXXXX_UXXXX. Where of course the Xs represent a number 0-9, and i need those 3 grouping of just numbers to put each into their respective column in the Datatable. I was initially intending to get the characters that represent each grouping and putting them together for each grouping but i’m wondering if there is a better way/quicker way than sending it to a charArray. Any suggestions?

  • 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-17T19:37:15+00:00Added an answer on May 17, 2026 at 7:37 pm

    Here is a relatively simple way to get the numbers out of test1 (without LINQ):

    ...
    string test1 = fi.Name.ToString();
    
    int baseFW=0;
    int activeFW=0;
    int upgradeFW=0;
    
    // Break the file name into the three groups
    string[] groups=test1.Split('_');
    
    if (groups.Length==3)
    {
      // Create a numbers array to hold the numbers
      int[] nums=new int[groups.Length];
    
      // Parse the numbers out of the strings
      int idx=0;
      foreach (string s in groups)
        nums[idx++]=int.Parse(s.Remove(0,1)); // Convert to num 
    
      baseFW=nums[0];
      activeFW=nums[1];
      upgradeFW=nums[2];
    }
    else
    {
      // Error handling...
    }
    

    If you want to do this using LINQ, it’s even easier:

    ...
    string test1 = fi.Name.ToString();
    
    int baseFW=0;
    int activeFW=0;
    int upgradeFW=0;
    
    // Extract all numbers
    int[] nums=test1.Split('_') // Split on underscores
                    .Select(s => int.Parse(s.Remove(0,1))) // Convert to ints
                    .ToArray(); // For random access, below
    
    if (nums.Length==3)
    {
      baseFW=nums[0];
      activeFW=nums[1];
      upgradeFW=nums[2];
    }
    else
    {
       // Error handling...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to sort a list using delegates but I am getting a
I would like to change database column names of a BDC list webpart using
I'm running the following code on a list of strings to return a list
I'm using APC for storing a map of class names to class file paths.
I am having a problem getting a list of fields from a query defined
Why am I getting a textbox that returns undefined list of variables? When I
I believe I'm getting bitten by some combination of nested scoping rules and list
I getting the following error when I try to connect to my server app
I have an XSLT transform I am using to process an XML file, inserting
Using Rails 3: In my update.js.erb file I found I was repeating a lot

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.