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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:04:28+00:00 2026-05-24T05:04:28+00:00

If I have a RichTextBox that is loaded from a file containg: TEXT MORETEXT

  • 0

If I have a RichTextBox that is loaded from a file containg:

TEXT MORETEXT 10.505  100.994 0  
TEXT MORETEXT -5.132  -12.994 90  
TEXT MORETEXT 100.001 -8.994  270  

and a TextBox that contains whatever the user enters in the textbox. Let’s say the user enters “10.005”.

My question is, how do I take this value and add it to the 3rd column containing the values 10.505, -5.132, 100.001. Once it is added, I would like to take the value and Replace the old value in the string. SO the updated RichTextBox would look like this.

TEXT MORETEXT 20.510  100.994 0  
TEXT MORETEXT 4.873  -12.994 90  
TEXT MORETEXT 110.006 -8.994  270  

RIGHT NOW I am able to strip the strings from the RichTextBox by using this code:

    private void calculateXAndYPlacementTwo()
    {
        // Reads the lines in the file to format.
        var fileReader = File.OpenText(filePath);

        // Creates a list for the lines to be stored in.
        var fileList = new List<string>();

        // Adds each line in the file to the list.
        while (true)
        {
            var line = fileReader.ReadLine();
            if (line == null)
                break;
            fileList.Add(line);
        }

        // 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 }));

                // Adds the values into the xResult and yResult lists.
                xResult.Add(xValue);
                yResult.Add(yValue);

                // Place the 'X' and 'Y' values into the proper RTB.
                xRichTextBox.AppendText(xValue + "\n");
                yRichTextBox.AppendText(yValue + "\n");
            }
        });
    }

To get the values in the xRichTextBox looking like:

10.505
-5.132
100.001

and the yRichTextBox looking like:

100.994
-12.994
-8.994

But I do not know how to turn those into values that can have addition used on them…


EDIT:
I have messed around with this some more… I am now using this code (below) to try to accomplish what I need it to do. This is only for the “X” (3rd column).

HOWEVER THIS CODE IS NOT WORKING (it concats the user input to the end of the xRichTextBox instead of mathematically adding it to each line..)

The xDisplacementTextBox is the user input and the xRichTextBox is the stripped values from the main string.

StringBuilder stringBuilder = new StringBuilder();
string[] Lines = xRichTextBox.Text.Split('\n');
double d = double.Parse(xDisplacementTextBox.Text);

for(int i = 0; i < Lines.Length; ++i)
{
    string newThing = double.Parse((Lines[i]) + d).ToString();
    stringBuilder.AppendLine(newThing);
}

xRichTextBox.Text = stringBuilder.ToString();

This is also not letting me enter in values that have decimals (ie. 50.005)..

  • 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-24T05:04:28+00:00Added an answer on May 24, 2026 at 5:04 am

    Look at double.Parse – as in
    double x = double.Parse(xValue);

    To expand, and do your work for you…

    double d = double.Parse(xDisplacementTextBox.Text);
    string[] Lines = xRichTextBox.Text.Split('\n');
    
    for(int i = 0; i < Lines.Length; ++i)
    {
        Match lineMatch = Regex.Match(lines[i], @"^(?<p>.*)(?<x>-?\d+\.\d+)(?<y>\s+-?\d+\.\d+\s+-?\d+\.\d+)$");
        if (lineMatch.Success)
        {
            double xValue = double.Parse(lineMatch.Groups["x"].Value) + d;
            lines[i] = lineMatch.Groups["p"] + xValue + lineMatch.Groups["p"];
        }
     }
     xRichTextBox.Text = string.Join(lines, '\n');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a RichTextBox that looks like this: TEXT NEXT_TEXT 10.505 -174.994 0 TEXT
I have a richtextbox that its text is a concatenation of some words from
I have a RichTextBox that looks similar to this: TEXT TEXT-1 227.905 174.994 180
I have a RTB that is loaded with a file that looks like this:
I have a method that is meant to display output on a RichTextBox in
I have a RichTextBox that I want to re-format when the contents of the
I have a RichTextBox that I'm spewing log information to, but the RichTextBox seems
I have a RichTextBox that I write a string to every time I click
I have a System.Windows.Forms.RichTextBox that I wish to use to display some instructions to
I have a Windows Forms application that on it I have a RichTextBox, like

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.