PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 5, 2022

[FIXED] How to trim unwanted letters from textbox continuously?

 September 05, 2022     c#, textbox, trim     No comments   

Issue

I am creating a project where the program fetches data from a serial port and displays it in a textbox. But along with the data, some unwanted characters are also getting inputted in the textbox through the serial port. I tried to trim them with '.Trim()' method by adding it in the textchanged event. But I could not get the desired outcome. I want the unwanted letters to get continuously trimmed from the textbox and the method should keep running in the background. Below is the code I tried out:

private void textBoxResults_TextChanged(...)
{
  char[] trim= ['a', 'b'];
  textBoxResults.Text.Trim(trim);
}

Please note that those are multiple letters(e.g. they could be g, m, a, etc.) I want all the unwanted ones to be trimmed from the textbox either directly when serialport data is received or after input from serial port.


Solution

Not exactly what all of you said, but something grouped after googling a bit.

string ToBeReplaceCharacters = @"a;b";
foreach(var RepChar in ToBeReplaceCharacters)
{
  textBox1.Text = textBox1.Text.Replace(RepChar.ToString(), "");
}

What Stackloyd said is ok for single character but not multiple characters to be replaced. The above code fulfils my demand.

Thank You All!



Answered By - D J
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing