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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:05:11+00:00 2026-05-24T02:05:11+00:00

EXPLANATION OF THE CODE BELOW: I am loading a .txt file and creating a

  • 0

EXPLANATION OF THE CODE BELOW:

  • I am loading a .txt file and creating a list to store it in.
  • The while loop stores all of the text into the list.
  • I create 3 more lists to store different values.
  • I use REGEX to match for numbers looking like “111.111”.
  • If it is a match in the line, group it as “X” and “Y”.
  • Add each of the grouped items to the new lists created above (the 3 of them).
  • Use addition on the “X” and “Y” values using a TextBox input value.
  • Output the StringBuilder values to RichTextBoxes.

    private void calculateXAndYPlacement()
    {s
        // Reads the lines in the file to format.
        var fileReader = File.OpenText(filePath + "\\Calculating X,Y File.txt");
    
        // Creates a list for the lines to be stored in.
        var fileList = new List<string>();
    
        // Adds each line in the file to the list.
        var fileLines = "";                                       #UPDATED @Corey Ogburn
        while ((fileLines = fileReader.ReadLine()) != null)       #UPDATED @Corey Ogburn
            fileList.Add(fileLines);                              #UPDATED @Corey Ogburn
    
        // Creates new lists to hold certain matches for each list.
        var xyResult = new List<string>();
        var xResult = new List<string>();
        var yResult = new List<string>();
    
        // Iterate over each line in the file and extract the x and y values
        fileList.ForEach(line =>
        {
            Match xyMatch = Regex.Match(line, @"(?<x>-?\d+\.\d+)\s+(?<y>-?\d+\.\d+)");
            if (xyMatch.Success)
            {
                // Grab the x and y values from the regular expression match
                String xValue = xyMatch.Groups["x"].Value;
                String yValue = xyMatch.Groups["y"].Value;
    
                // Add these two values, separated by a space, to the "xyResult" list.
                xyResult.Add(String.Join(" ", new[]{ xValue, yValue }));
    
                // Add the results to the lists.
                xResult.Add(xValue);
                yResult.Add(yValue);
    
                // Calculate the X & Y values (including the x & y displacements)
                double doubleX = double.Parse(xValue);
                double doubleXValue = double.Parse(xDisplacementTextBox.Text);
                StringBuilder sbX = new StringBuilder();
    
                sbX.AppendLine((doubleX + doubleXValue).ToString());
    
                double doubleY = double.Parse(yValue);
                double doubleYValue = double.Parse(yDisplacementTextBox.Text);
                StringBuilder sbY = new StringBuilder();
    
                sbY.AppendLine((doubleY + doubleYValue).ToString());
    
                calculatedXRichTextBox.AppendText(sbX + "\n");
                calculatedYRichTextBox.AppendText(sbY + "\n");
            }
        });
    }
    

NOW::: What I am trying to do is take these new values that are in the calculatedXRichTextBox and calculatedYRichTextBox and Replace the old values (in the fileList) and output them to override the calculatedXRichTextBox and calculatedYRichTextBox.

SO, the values I have are:

(original file)

TEXT   TEXT  227.905  203.244  180  
TEXT   TEXT  242.210  181.294  180  
TEXT   TEXT  236.135  198.644  90  

(stripped values “X” and “Y” — in 2 different lists)

227.905                      203.244  
242.210                      181.294  
236.135                      198.644  

(calculated value adding “10” to “X” and “20” to “Y” — placing them into 2 different RichTextBoxes)

237.905                      223.244
252.210                      201.294
246.135                      218.644

(THIS IS WHAT I WANT TO END UP WITH — the original file + calculated values replacing old values)

TEXT   TEXT  237.905  223.244  180  
TEXT   TEXT  252.210  201.294  180  
TEXT   TEXT  246.135  218.644  90  

QUESTIONS:

  • How can I do this?
  • 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-24T02:05:13+00:00Added an answer on May 24, 2026 at 2:05 am

    Another way to approach your problem is to think of your code as applying a transformation to a stream of data.

    That’s basically what the sample below does. It was written for .NET 4.0, if you are targeting an earlier runtime you’ll have to use the ReadAllLines method (as opposed to ReadLines) and instead of using a Tuple you’ll need to make a container class (which can be private to this class) to return multiple values from your function.

    void calculateXAndYPlacement()
    {
        // Read data from file
        var path = @"[path to your document]";
        var data = File.ReadLines(path + "data.txt");
    
        // Parse the values you'll be modifying your data by
        var doubleXValue = double.Parse(xDisplacementTextBox.Text);
        var doubleYValue = double.Parse(yDisplacementTextBox.Text);                     
    
        // apply your transformation to all valid lines of data
        var modifiedData = from line in data
                           where LineIsValid( line )
                           select ModifyLine( line, doubleXValue, doubleYValue );
    
        // Do what you wish with the data
        foreach( var dataPoint in modifiedData )
        {
             // grab the values from the Tuple and put them into the
             // appropriate text boxes.
        }
    }
    
    Tuple<string,double,double> ModifyLine(string data, double xValue, double yValue)
    {
        // split line into parts
        var columns = Regex.Split(data, @"\s+");
        columns.Dump();
        // do your math on each part, I just assigned the new values
        // for the sake of the example.
        columns[3] = xValue.ToString();
        columns[4] = yValue.ToString();
    
        // recombine the line
        return Tuple.Create( string.Join(" ", columns), xValue, yValue );
    }
    
    bool LineIsValid(string lineData)
    {
        return Regex.IsMatch(lineData, @"(?<x>-?\d+\.\d+)\s+(?<y>-?\d+\.\d+)");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

tl;dr; Even without my explanation one can look at the code below and the
Update: The code below does indeed work as expected, and accomplishes the code I
So in the example code below, I create a UserControl UserControldChild which is a
Drawing more than ~5+ SVG lines with the code below makes performance choppy when
I have a problem understanding what's causes the compilation error in the code below:
Despite the fact that my JDO query contains TWO declareParameters statements, the code below
I've wrote simple RMI code to learn how it works. While everything works fine
SOLUTION BELOW I've been looking all over the net to find a solution for
the code below belongs to binary search algorithm,user enter numbers in textbox1 and enter
The code below belongs to a binary search algorithm. The user enters numbers in

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.