- This topic helps to search character from textbox using C# programming.
- Helps to find a character included in the textbox or richtextbox using C# programming.
- Tools needed for search character from textbox: TextBox1 (TextBox1), TextBox2 (TextBox2), Button1 (Button1).
- Here we search a character “a” from the TextBox using C# programming with the help of string Builder.
TextBox Class – Search character from textbox using C#
- It represents a control that can be used to display or edit unformatted text.
- Syntax for Search character from textboxin C#
|
1 2 3 4 5 |
// Declaration [LocalizabilityAttribute(LocalizationCategory.Text)] [ContentPropertyAttribute("Text")] public class TextBox : TextBoxBase, IAddChild { } |
System.Text Namespace – Search character from textbox using C#
- The System.Text namespace contains classes that represent ASCII and Unicode character encodings.
- Abstract base class for converting blocks of characters to and from blocks of bytes.
- A helper class that manipulates and formats String objects without creating intermediate instances of String.
System.Text.StringBuilder – Search character from textbox using C#
- StringBuilder represents a mutable string of characters. This class cannot be inherited.
Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
- Syntax for StringBuilder
|
1 2 3 4 5 |
// Declaration [SerializableAttribute()] [ComVisibleAttribute(true)] public sealed class StringBuilder : ISerializable { } |
StringBuilder.Append Method (Char) – Search character from textbox using C#
- This method appends the string representation of a specified Unicode character to this instance.
Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
- Syntax for Append Method
|
1 2 3 |
// Declaration public StringBuilder Append(char value) { } |
Search character from textbox using C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void BtnSearch_Click(object sender, EventArgs e) { string str = null; str = textBox1.Text; System.Text.StringBuilder sb1 = new System.Text.StringBuilder(); foreach (char ch in str) { if (ch.ToString() == "a") { sb1.Append(ch); } } textBox2.Text = sb1.ToString(); } } } |

Search character from textbox in C# – Design the form as shown in this figure
If you have any suggestions regarding this topic search character from textbox, please inform us…
Search character from textbox using C#






