Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Replace a character with nothing

I have a RichTextBox that looks like this:

TEXT  NEXT_TEXT  10.505   -174.994 0 TEXT  NEXT_TEXT  100.005  174.994  90  TEXT  NEXT_TEXT  -10.000  -5.555   180 TEXT  NEXT_TEXT  -500.987 5.123    270 TEXT  NEXT_TEXT  987.123  1.000    180 TEXT  NEXT_TEXT  234.567  200.999  90 

and I want to replace the "." with nothing and place it into a ListBox...

So the new file would look like this:

TEXT  NEXT_TEXT  10505   -174994 0 TEXT  NEXT_TEXT  100005  174994  90  TEXT  NEXT_TEXT  -10000  -5555   180 TEXT  NEXT_TEXT  -500987 5123    270 TEXT  NEXT_TEXT  987123  1000    180 TEXT  NEXT_TEXT  234567  200999  90 

I thought about multiplying the values by 1000 but I do not know how to properly do match calculations on a string.

So the next thought was to do this (HOWEVER THIS DOES NOT WORK):

  // Splits the lines in the rich text boxes   string[] listOneLines = oneRichTextBox.Text.Split('\n');    // Set the selection mode to multiple and extended.   placementOneListBox.SelectionMode = SelectionMode.MultiExtended;    // Shutdown the painting of the ListBox as items are added.   placementOneListBox.BeginUpdate();    // Display the items in the listbox.   foreach (var item in listOneLines)   {       item.Replace(".","");       placementOneListBox.Items.Add(item);   }    // Allow the ListBox to repaint and display the new items.   placementOneListBox.EndUpdate(); 

  • Can anyone help me figure out how to replace a "."?
like image 584
theNoobGuy Avatar asked Jul 26 '11 20:07

theNoobGuy


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.


1 Answers

Strings are immutable so this line is wrong:

item.Replace(".",""); 

This returns the string after the replacement has been made, but item is unchanged. You need this:

foreach (var item in listOneLines)     placementOneListBox.Items.Add(item.Replace(".","")); 
like image 133
David Heffernan Avatar answered Sep 24 '22 03:09

David Heffernan