I'm a newbie to here. and i don't have any expirience in coding.I was stuck in coding part of my project.I have done it in C# in visual studio
I wanted to search a string typed in text box in a file that is open as another string which is a source code. And i wanted to check the typed string is there before a 20 characters in front of the word "$_POST" which is in the source code.and if the string is there, print something. I have attached the code until i have done.Please help me.
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;
using System.IO;
namespace XSS_Prevention_Tool
{
public partial class Home : Form
{
int count = 0,lc=0;
string language;
public Home()
{
InitializeComponent();
}
private void Home_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
languageSelection();
folderBrowserDialog1.ShowDialog();
txtpath.Text= folderBrowserDialog1.SelectedPath.ToString();
ColumnHeader header1 = new ColumnHeader();
header1.Text = " Scanning: ";
header1.Width = listFiles.ClientSize.Width;
listFiles.Columns.Add(header1);
DirSearch(folderBrowserDialog1.SelectedPath.ToString());
}
private void languageSelection()
{
if (rdoASP.Checked == true)
{
language = "asp";
}
else if (rdoJSP.Checked == true)
language = "jsp";
else if (rdoPHP.Checked == true)
language = "php";
else
MessageBox.Show("Select a language");
lblLanguage.Text = language;
textBox2.Visible = true;
}
public void DirSearch(string dir)
{
try
{
foreach (string f in Directory.GetFiles(dir))
{
string e = Path.GetExtension(f);
if (e == "."+language)
{
listFiles.Items.Add(f);
lc++;
textBox2.Text = lc.ToString();
XSS(f);
}
count++;
textBox1.Text = count.ToString();
}
foreach (string d in Directory.GetDirectories(dir))
{
DirSearch(d);
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void XSS(string f)
{
String methode = "$_POST";
System.IO.StreamReader myFile = new System.IO.StreamReader(f);
string myString = myFile.ReadToEnd();
myFile.Close();
if (myString.Contains(methode))
{
int pos = myString.IndexOf(methode);
MessageBox.Show(pos.ToString());
}
}
private void label2_Click(object sender, EventArgs e)
{
}
private void listFiles_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void txtpath_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
}
}
I assume you need to find the substring within a string. Just go through these examples and try to find a solution.
http://www.dotnetperls.com/substring
Substring in C# string Class returns a new string that is a substring of this string. The substring begins at the specified given index and extended up to the given length.
string string.substring(int startIndex,int length)
Parameters:
startIndex: The index of the start of the substring.
length: The number of characters in the substring.
Returns:
The specified substring.
Exceptions:
System.ArgumentOutOfRangeException : the beginIndex or length less than zero, or the begin index + length not within the specified string
Related
I have these textboxes named bags,rate,quantity,packing size and amount what i want to do is that when user enters bags and rate and packing size the quantity textbox should automatically shows the corresponding quantity and amount but in my case when i click on calculate button then it calculates and show the quantity and amount i have tried using textchanged event but it does not do the job?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Login
{
public partial class Sale : Form
{
SaleCalci sale;
SaleBillheader SaleHeaderModel = new SaleBillheader();
tbl_SaleBillDetails SaleDetailModel = new tbl_SaleBillDetails();
public Sale()
{
InitializeComponent();
}
private void Cancelbtn_Click(object sender, EventArgs e)
{
clear();
}
private void clear()
{
txtBillNo.Text = txtDesc.Text = "";
txtBags.Text = txtQty.Text = txtRate.Text = txtAmt.Text = "0.00";
if(txtQty.Text !=null && txtAmt.Text !=null )
{
txtQty.Text = "0.00";
txtAmt.Text = "0.00";
}
Savebtn.Text = "Save";
SaleHeaderModel.SaleBillHeaderId = 0;
SaleDetailModel.SaleBill_Id = 0;
}
private void Exitbtn_Click(object sender, EventArgs e)
{
var result = MessageBox.Show("Are you sure you want to close this form ?", "Confirm", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{ this.Close(); }
}
private void Sale_Load(object sender, EventArgs e)
{
ItemCombo();
PartyCombo();
PackingSizeCombo();
// clear();
}
private void ItemCombo()
{
UserDataEntities db = new UserDataEntities();
Itembox.DataSource = db.tbl_ItemId.ToList();
Itembox.ValueMember = "ItemId";
Itembox.DisplayMember = "ItemName";
}
private void PartyCombo()
{
UserDataEntities db = new UserDataEntities();
PartyBox.DataSource = db.tbl_Parties.ToList();
PartyBox.ValueMember = "Id";
PartyBox.DisplayMember = "PartyName";
}
private void PackingSizeCombo()
{
UserDataEntities db = new UserDataEntities();
PackingBox.DataSource = db.PackingSizes.ToList();
PackingBox.ValueMember = "PackingSizeId";
PackingBox.DisplayMember = "PackingSize1";
}
private void Savebtn_Click(object sender, EventArgs e)
{
CalculateAmount();
DisplayAmt();
}
private void CalculateAmount()
{
int bags = 0;
decimal rate = 0;
int pksize = 0;
bags = Convert.ToInt32(txtBags.Text);
rate = Convert.ToDecimal(txtRate.Text);
pksize = Convert.ToInt32(PackingBox.Text);
sale = new SaleCalci(bags,rate, pksize);
//sale.Bags = Convert.ToInt32(txtBags.Text);
//sale.Rate = Convert.ToDecimal(txtRate.Text);
//SaleDetailModel.Bags = int.Parse(txtBags.Text.Trim());
//SaleDetailModel.Qty = Convert.ToDecimal(txtQty.Text.Trim());
//SaleDetailModel.Rate = Convert.ToDecimal(txtRate.Text.Trim());
// SaleDetailModel.Amount = amount;
}
private void txtAmt_TextChanged(object sender, EventArgs e)
{
// txtAmt.Text = sale.CalucalteAmt.ToString();
}
private void Sale_Click(object sender, EventArgs e)
{
if ((txtBags.Text == "0.00") && (txtQty.Text == "0.00")&&(txtRate.Text == "0.00")&& (txtAmt.Text =="0.00"))
{
txtAmt.Clear();
txtBags.Clear();
txtQty.Clear();
txtRate.Clear();
}
}
private void txtQty_TextChanged(object sender, EventArgs e)
{
DisplayAmt();
}
private void txtBags_TextChanged(object sender, EventArgs e)
{
// sale.Bags = Convert.ToInt32(txtBags.Text);
// DisplayAmt();
}
private void PackingBox_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void txtRate_TextChanged(object sender, EventArgs e)
{
// DisplayAmt();
}
private void DisplayAmt()
{
decimal _amt = sale.CalucalteAmt;
txtQty.Text = sale.CalculateQty().ToString();
txtAmt.Text = _amt.ToString();
}
}
}
Normally "TextChanged" event fires autamatically if text value changes.
So here the problem is i think about your other "partial class" in which there has to exist eventhandler work. Something like:
txtBags.TextChanged += new EventHandler(txtBags_TextChanged);
Please check your other partial class if this staement exist.
This eventhandler sometimes disappears from project if you move your gui elements or for some other causes...
You can readd this statement manually.
By the way if you have not experience with the other partial class then you can try to remove these textboxes and re-add them then your problem will autamatically solves.
You need to call DisplayAmt in the TextChanged event of txtBags , txtRate and Size. In the code above, call to DisplayAmt is commented out. Instead, you are calling DisplayAmt in the TextChanged event of txtQty.
You should be, instead doing.
private void txtAmt_TextChanged(object sender, EventArgs e)
{
DisplayAmt();
}
private void txtRate_TextChanged(object sender, EventArgs e)
{
DisplayAmt();
}
Similarly, you need to add Changed event for Text Control for Size. The txtQty is updated by the DisplayAmt() method. So you don't necessarily need it, unless for reasons that are not specified in OP.
I have made a simple TO-DOs program that gets input from a text box then place it in another text box. With tick boxes next to it,
this is all fine except i Cannot save the list eg. the item and if it's finished or not.
Please could anyone help me be able to save this list of items.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TO_DOs
{
public partial class Form1 : Form
{
private bool text1, text2, text3, text4, text5, text6, text7, text8;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (text1 == false)
{
textBox2.Text = textBox1.Text;
}
else if (text2 == false)
{
textBox3.Text = textBox1.Text;
}
else if (text3 == false)
{
textBox4.Text = textBox1.Text;
}
else if (text4 == false)
{
textBox5.Text = textBox1.Text;
}
else if (text5 == false)
{
textBox6.Text = textBox1.Text;
}
else if (text6 == false)
{
textBox7.Text = textBox1.Text;
}
else if (text7 == false)
{
textBox8.Text = textBox1.Text;
}
else if (text8 == false)
{
textBox9.Text = textBox1.Text;
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
text1 = true;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
text2 = true;
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
text3 = true;
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
text4 = true;
}
private void textBox6_TextChanged(object sender, EventArgs e)
{
text5 = true;
}
private void textBox7_TextChanged(object sender, EventArgs e)
{
text6 = true;
}
private void textBox8_TextChanged(object sender, EventArgs e)
{
text7 = true;
}
private void textBox9_TextChanged(object sender, EventArgs e)
{
text8 = true;
}
}
}
I would do it like this:
Create a class to store your values in:
public class ListEntry
{
public string Text { get; set; }
public bool Finished { get; set; }
}
Then I would create 2 Methods:
public List<ListEntry> UI_To_List(); //Create UI from your saved file
public void List_To_UI(List<ListEntry> entries); //Process your UI
Now it's your choice on how to store your list.
You could store it as JSON or XML.
A few recommendations:
I would create a UserControl for your TextBox + CheckBox
Display the 'List of UserControls' in a FlowLayoutPanel
=> then you can process the FlowLayoutPanel.Controls List.
This will make your List dynamically size to an 'unlimited' amount of items.
Short example:
Create a UserControl (Rightclick project for that):
Add these 2 methods to the code of your UserControl (F7 / rightclick => View Code):
public void SetText(string text)
{
//Set the Text of your TextBox in the UserControl:
textBox1.Text = text;
}
public void SetFinished(bool finished)
{
//Set the Checked of your CheckBox in the UserControl:
checkBox1.Checked = finished;
}
In your MainForm add an FlowLayoutPanel (from ToolBox).
Add your Data like this (using class from above):
/// <summary>
///
/// </summary>
/// <param name="entries">You will get them from loading your previously saved file</param>
public void CreateUI(List<ListEntry> entries)
{
foreach (ListEntry entry in entries)
{
//Create new instance of your UserControl
TaskView view = new TaskView();
view.SetFinished(entry.IsFinished);
view.SetText(entry.Text);
//Add that to your UI:
this.flowLayoutPanel1.Controls.Add(view);
}
}
The result will look like this:
I'm not sure what exactly it is that you want to save in a list... but here's just a tip when checking conditions, instead of using if (text1 == false), simply do if (!text1) as this means "is not true" because by default if (text1) will return true.
private void button1_Click(object sender, EventArgs e)
{
if (!text1)
{
textBox2.Text = textBox1.Text;
}
else if (!text2)
{
textBox3.Text = textBox1.Text;
}
// Left out the rest of the else ifs
}
You are casting textboxes wrong. For example when you change textBox4, you gave text3 true.
private void textBox4_TextChanged(object sender, EventArgs e)
{
text3 = true;
}
Then you cast
TextBox4.Text = TextBox1.Text;
It changes TextBox4.Text to TextBox1.Text.
You probably want to save TextBox4.Text here at TextBox1.Text so you sould change all if blocks like that. So you have to give only one "true" function for changed textBox sign and change if blocks
if(text(boolNum))
TextBox1.Text = TextBox(Number).Text;
Just swap them and try like that.
If you want to save another thing by another way. You have to be more spesific.
You can use a CheckedListbox to hold all tot actions.
You can then tick the itemsand for instance in the OK button you include a save action:
foreach(var item in MyCheckedListbox.CheckedItems)
{
Console,WriteLine(item.Text);
}
Lets see the answer from Felix D. He tells you exactly how to create a class and save the items into it. But now you only have a List that will be available as long as your software is running. You still need to save it somewhere on your desktop.
Lucky for you, you got a really simple pattern.
string; boolean
So how about you make it yourself simple? Just create a textfile and write your entries, as example in a csv marked with a ; for every information?
Example:
class Program
{
public class tmpClass
{
public string Text;
public bool tick;
}
public List<tmpClass> tmpList = new List<tmpClass>();
static void Main(string[] args)
{
//Stuff
}
public void WriteToFile()
{
string tmpTextFilePath = #"C:\User\Desktop\SaveText.txt";
using (StreamWriter tmpWriter = new StreamWriter(tmpTextFilePath))
{
string tmpTextToWrite = String.Empty;
for (int i = 0; i < tmpList.Count; i++)
{
tmpClass tmpEntry = tmpList[i];
tmpTextToWrite += tmpEntry.Text + ";" + tmpEntry.tick;
}
tmpWriter.WriteLine(tmpTextToWrite);
}
//Now we wrote a text file to you desktop with all Informations
}
public void ReadFromFile()
{
string tmpTextFilePath = #"C:\User\Desktop\SaveText.txt";
using (StreamReader tmpReader = new StreamReader(tmpTextFilePath))
{
string tmpText = tmpReader.ReadLine();
string tmpInput = String.Empty;
tmpClass tmpClass = new tmpClass();
int i = 0;
foreach (char item in tmpText)
{
if(item.Equals(";".ToCharArray()))
{
if (i == 0)
{
tmpClass.Text = tmpInput;
i = 1;
tmpInput = String.Empty;
}
else
{
if (tmpInput == "True")
tmpClass.tick = true;
else
tmpClass.tick = false;
i = 0;
tmpInput = String.Empty;
tmpList.Add(tmpClass);
}
}
tmpInput += item;
}
}
}
}
This should simply write a txt File to your desktop with your information and read one and save it to your list.
What I have to do is this:
Make an image gallery that has 5 buttons which each one select a folder of images.
Other two buttons for next and previous of the folder you are in. In my line 76, it says
argument 1: cannot convert from 'System.collection.Generic.list' to string
Any ideas?
Here's an image of the console
http://postimg.org/image/nct5pwdit/
Line 76 says:
pictureBox1.Load(semestres[semac].imagen[]);
I have the same command like 6 times.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
class semestres
{
public List<string> imagen = new List<string>();
private int _semestre;
public int canti;
public int actual;
public int c;
public semestres(int semestre, List<string> imagenes)
{
_semestre = semestre;
imagen = imagenes;
c = imagen.Count;
actual = 0;
}
public int semestre
{
get
{
return _semestre;
}
set
{
c = imagen.Count;
}
}
public int can
{
get
{
return c;
}
set
{
c = imagen.Count;
}
}
}
namespace Visor
{
public partial class Form1 : Form
{
private int cont;
private int semac;
private int _cant;
private int next;
private List<semestres> semestres = new List<semestres>();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
cont = semestres[semac].actual;
cont--;
if (cont >= 0)
{
pictureBox1.Load(semestres[semac].imagen[]);
semestres[semac].actual = cont;
}
else
{
// MessageBox("Esta es la primer imagen");
cont = 0;
semestres[semac].actual = cont;
pictureBox1.Load(semestres[semac].imagen);
}
}
private void button7_Click(object sender, EventArgs e)
{
cont = semestres[semac].actual;
next = semestres[semac].c;
cont++;
if (cont < next)
{
pictureBox1.Load(semestres[semac].imagen);
semestres[semac].actual = cont;
}
else
{
// MessageBox("Esta es la ultima imagen");
cont--;
semestres[semac].actual = cont;
pictureBox1.Load(semestres[semac].imagen(cont));
}
}
private void button2_Click(object sender, EventArgs e)
{
semac = 0;
try
{
if (semestres[0].c > 0)
{
cont = semestres[0].actual;
pictureBox1.Load(semestres[0].imagen(cont));
}
}
catch (Exception)
{
OpenFileDialog file = new OpenFileDialog();
file.InitialDirectory = #"C:\";
file.Filter = "Images (*.BMP; *.JPG; *.GIF)|*.BMP; *.JPG; *.GIF|" + "All files(*.*)|*.*";
file.FilterIndex = 1;
file.Multiselect = true;
file.RestoreDirectory = true;
file.ShowDialog();
string[] imgs = file.FileNames;
List<string> imagenes = new List<string>();
foreach (string imagen in imgs)
{
imagenes.Add(imagen);
}
semestres.Add(new semestres(1, imagenes));
pictureBox1.Load(imagenes[0]);
semestres[0].actual = 0;
cont = 0;
}
}
private void button6_Click(object sender, EventArgs e)
{
}
private void btn_3_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn_sal_Click(object sender, EventArgs e)
{
}
private void btn_2_Click(object sender, EventArgs e)
{
}
}
}
So you have this:
pictureBox1.Load(semestres[semac].imagen);
Well the problem is that imagen is a List<string>. Picturebox.Load(string) takes a string, not a List<string>. So you need to get a string from that list instead of passing the whole list. One way would be:
pictureBox1.Load(semestres[semac].imagen[0]);
This would load the first image in that list.
Alternatively, you might be trying to do:
pictureBox1.Load(semestres[semac].imagen[cont]);
You just need to determine what the correct index is that you're trying to specify.
items searched in search function: the ALBUMS dont get added to the list box?
the other fields populate
can you please tell me how i can populate the listbox with the searched albums
albums be looked up using a linked list
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Assignment
{
public partial class frmAddArtist : Form
{
AVLTree<Artist> avltree = new AVLTree<Artist>();
LinkedList<Album> temp = new LinkedList<Album>();
Artist artistinst;
Album albuminst;
string noofmembers, artistname;
int artistcount;
public frmAddArtist()
{
InitializeComponent();
}
private void label5_Click(object sender, EventArgs e)
{
}
private void btnAddArtist_Click(object sender, EventArgs e)
{
string tempalbum, date;
tempalbum = txtAlbumName.Text;
date = dtpReleaseDate.Text.ToString();
albuminst = new Album(tempalbum, date);
temp.AddFirst(albuminst);
lbAlbums.Items.Add(tempalbum);
}
private void btnSave_Click(object sender, EventArgs e)
{
artistname = txtArtistName.Text;
noofmembers = txtNoOfMembers.Text;
artistinst = new Artist(artistname, noofmembers, temp);
avltree.InsertItem(artistinst);
artistcount++;
txtArtistName.Clear();
txtNoOfMembers.Clear();
txtAlbumName.Clear();
lbAlbums.Items.Clear();
temp.Clear();
}
private void btnNoOfArtist_Click(object sender, EventArgs e)
{
MessageBox.Show("The No. Artist: " + Convert.ToString(artistcount));
}
private void btnHeight_Click(object sender, EventArgs e)
{
int heightoftree = avltree.Height();
string height = Convert.ToString(heightoftree);
MessageBox.Show("The Height of the Tree: " + height);
}
private void btnSearch_Click(object sender, EventArgs e)
{
Artist temp = new Artist(txtSearch.Text, " ", null);
Artist result = avltree.Search(temp);
if (result != null)
{
if (result.CompareTo(temp) == 0)
{
txtArtistName.Text = result.artistname;
txtNoOfMembers.Text = result.noofmembers;
foreach (Album p in result.Albumslist)
{
lbAlbums.Items.Add(p.Albumname);
}
}
else if(result.CompareTo(temp) <0)
{
MessageBox .Show("No Match Found");
}
}
}
}
}
Put the items into a LinkedList or a List.
Then set lbAlbums.ItemsSource=;
I want to add texts / descriptions after the RFID reader has scanned some tags. I tried using the IF statements but it did nothing.
Its output are the tag numbers but the texts I wanted to add didnt show or display. Please help, thanks!
I want the output to be 00000919BEAE = Milk
Here's our code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
Dictionary<string, string> tags = new Dictionary<string, string>() {
{ "00000919BEAE", "Milk" } ,
{"0000092A1132", "Fruits"}};
public string RxString;
public Form1()
{
InitializeComponent();
}
private void buttonStart_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM15";
serialPort1.BaudRate = 9600;
serialPort1.Open();
if (serialPort1.IsOpen)
{
buttonStart.Enabled = false;
buttonStop.Enabled = true;
textBox1.ReadOnly = false;
}
}
private void buttonStop_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
buttonStart.Enabled = true;
buttonStop.Enabled = false;
textBox1.ReadOnly = true;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// If the port is closed, don't try to send a character.
if(!serialPort1.IsOpen) return;
// If the port is Open, declare a char[] array with one element.
char[] buff = new char[1];
// Load element 0 with the key character.
buff[0] = e.KeyChar;
// Send the one character buffer.
serialPort1.Write(buff, 0, 1);
// Set the KeyPress event as handled so the character won't
// display locally. If you want it to display, omit the next line.
e.Handled = true;
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(RxString);
if (tags.ContainsKey(RxString))
{
Console.Write(tags[RxString]); // this will print Milk
}
}
private void serialPort1_DataReceived
(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
RxString = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
}
}
Try making RxString and the value you are comparing it to both uppercase, like this:
if (RxString.ToUpper() == tagid1.ToUpper())
{
string milk = "Milk";
Console.Write(milk);
}
if (RxString.ToUpper() == tagid2.ToUpper())
{
string fruits = "Fruits";
Console.Write(fruits);
}
if (RxString.ToUpper() == tagid3.ToUpper())
{
string soda = "Soda";
Console.Write(soda);
}
if (RxString.ToUpper() == tagid4.ToUpper())
{
string meat = "Meat";
Console.Write(meat);
}
I want the output to be 000A1234D980 = Milk
but you have condition
if (RxString == tagid1)
{
string milk = "Milk";
Console.Write(milk);
}
tagid1 is equal to "00000919BEAE", so your condition will fail.
debug and see which value exactly you get for RxString you can find the answer why your condition fail
Update :
You can use Dictionary for this
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("00000919BEAE", "Milk");
tags.Add("0000092A1132", "Fruits");
in your DisplayText method you can check for RxString key exist in the tag dictionary and if exist you can print
if (tags.ContainsKey(RxString))
{
Console.Write(tags[RxString]); // this will print Milk
}
Sample code :
public partial class Form1 : Form
{
Dictionary<string, string> tags = new Dictionary<string, string>() {
{ "00000919BEAE", "Milk" } ,
{"0000092A1132", "Fruits"}};
public string RxString { get; set; }
public Form1()
{
InitializeComponent();
}
private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(RxString);
if (tags.ContainsKey(RxString))
{
textBox1.AppendText(RxString + ":" + tags[RxString]);
}
}
}