I'm doing a school project where I need to pass notes (char, ascii) using a C# code in VS to an Altera card using a RS232 cable. when I'm sending a single note('A') the data goes through just fine but when I'm trying to send two notes at the same time ("AB") the data isn't receive well enough and I'm getting multiple problems like the wrong Leds turning on and off.
My VHDL code
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity UART_RX is
-- clockls per bit = 50Mhz/9600baudrate
generic(
gClocks_per_Bit : integer := 5208
);
port(
iClk : in std_logic;
iReset : in std_logic;
iRX : in std_logic:='0';
led1,led2 : out std_logic:='0';
oTX : out std_logic_vector (7 downto 0)
);
end UART_RX;
architecture Behavioral of UART_RX is
type uart_rx_type is (idle,start,data,stop);
signal sNext_state : uart_rx_type := idle;
signal sClock_counter : integer range 0 to gClocks_per_Bit := 0;
signal sIndex : integer range 0 to 15 := 0;
signal sTemp : std_logic_vector (15 downto 0);
signal receiver1, receiver2 : std_logic_vector (7 downto 0);
signal oTX_1 : std_logic_vector (7 downto 0);
begin
process(iClk,iReset)
begin
if(iReset = '0') then
sIndex <= 0;
sClock_counter <= 0;
elsif(rising_edge(iClk)) then
case sNext_state is
when idle =>
sClock_counter <= 0;
sIndex <= 0;
if(iRX = '0') then
sNext_state <= start;
elsif(iRX = '1') then
sNext_state <= idle;
end if;
when start =>
if(sClock_counter < gClocks_per_Bit) then
sClock_counter <= sClock_counter + 1;
if(sClock_counter = gClocks_per_Bit/2 AND iRX ='0') then
sNext_state <= start;
elsif(sClock_counter = gClocks_per_Bit/2 AND iRX ='1') then
sClock_counter <= 0;
sNext_state <= idle;
end if;
sNext_state <= start;
else
sClock_counter <= 0;
sNext_state <= data;
end if;
when data =>
if(sClock_counter < gClocks_per_Bit) then
sClock_counter <= sClock_counter + 1;
sNext_state <= data;
if(sClock_counter = gClocks_per_Bit/2) then
sTemp(sindex)<= iRX;
end if;
else
sClock_counter <= 0;
if(sIndex < 15) then
sIndex <= sIndex + 1;
sNext_state <= data;
else
sIndex <= 0;
sNext_state <= stop;
end if;
end if;
when stop =>
if(sClock_counter = gClocks_per_Bit / 2) then
sClock_counter <= 0;
sNext_state <= idle;
elsif(sClock_counter < gClocks_per_Bit) then
sClock_counter <= sClock_counter + 1;
end if;
when others => null;
end case;
end if;
end process;
receiver1<=sTemp(7 downto 0);
receiver2<=sTemp(15 downto 8);
-- oTX <= sTemp;
process(receiver1,receiver2,iReset)
begin
if iReset = '0' then
led2<='0';
led1<='0';
elsif receiver1 = "01000001" then -- A (led 1 on)
led2 <= '0';
led1 <= '1';
elsif receiver1 = "01000010" then -- B
led2 <= '1';
led1 <= '0';
elsif receiver1 = "01000011" then -- C
led2 <= '0';
led1 <= '0';
elsif sTemp = "0100000101000010" then -- AB
led2 <= '1';
led1 <= '1';
else -- What Ever You Write Turns Off/On Leds.
null;
end if;
end process;
oTX <= sTemp(7 downto 0);
end Behavioral ;
My C# 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;
using System.IO.Ports;
using System.Threading;
namespace COMPORT
{
public partial class Form1 : Form
{
string dataOUT;
public Form1()
{
InitializeComponent();
}
private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
serialPort1.PortName = cBoxCOMPORT.Text;
serialPort1.BaudRate = Convert.ToInt32(CBoxBaudRate.Text);
serialPort1.DataBits = Convert.ToInt32(cBoxDataBits.Text);
serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cBoxStopBits.Text);
serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), cBoxParityBits.Text);
serialPort1.Open();
progressBar1.Value = 100;
}
catch (Exception err)
{
MessageBox.Show(err.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnClose_Click(object sender, EventArgs e)
{
if(serialPort1.IsOpen)
{
serialPort1.Close();
progressBar1.Value = 0;
}
}
private void Form1_Load(object sender, EventArgs e)
{
string[] ports = SerialPort.GetPortNames();
cBoxCOMPORT.Items.AddRange(ports);
}
private void btnSendData_Click(object sender, EventArgs e)
{
if(serialPort1.IsOpen)
{
dataOUT = tBoxDataOut.Text;
//dataOUT = ConvertToHex(dataOUT);
//dataOUT = hex2binary(dataOUT);
serialPort1.Write(dataOUT);
Thread.Sleep((int)TimeSpan.FromSeconds(2).TotalMilliseconds);
MessageBox.Show(dataOUT);
}
}
private void tBoxDataOut_TextChanged(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
this.Text = DateTime.Now.ToString();
}
//public static string ConvertToHex(string asciiString)
//{
// string bin = "";
// foreach (char c in asciiString)
// {
// int tmp = c;
// bin += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));
// }
// return bin;
//}
//private string hex2binary(string hexvalue)
//{
// string binaryval = "";
// binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 2);
// return binaryval;
//}
}
}
thanks in advance
Tried looking online but what I look for is really specific.
Your receiver process does not assign a value to led1, led2 in all cases. That means in hardware you will get latches for these 2 signals (look into the synthesize messages). The enable of each latch is controlled by a big combinatorial logic, which looks at reveiver1 and sTemp (and iReset). While these multi-bit signals change their values you will have glitches at the latch enable signal at any time which will store unexpected values in the latches. So assign a value to led1/2 in all cases.
Related
I'm trying to give the letters in my richtextbox different colors for my subnet calculator, but the richtextbox doesn't change the colors until the 26th letter.
How it looks:
int iValueSm = trackBarSmMask.Value;
rtbScroll.Text = "";
rtbScroll.SelectionStart = rtbScroll.TextLength;
rtbScroll.SelectionLength = 0;
for (int i = 1; i <= iValueSm; i++)
{
rtbScroll.SelectionColor = Color.Blue;
rtbScroll.AppendText("N");
if (i%8==0 && i != 32)
{
rtbScroll.Text = rtbScroll.Text + ".";
}
}
for (int i = iValueSm+1; i <= 32; i++)
{
rtbScroll.SelectionColor = Color.Red;
rtbScroll.AppendText("H");
if (i % 8 == 0 && i != 32)
{
rtbScroll.Text = rtbScroll.Text + ".";
}
}
labelAmountNetID.Text = "/" + iValueSm.ToString();
Well, can be a lot of approaches to deal with this problem but here is one suggestion:
// Track bar definitions...
private void SetTrackBarVals()
{
trackBar1.Minimum = 0;
trackBar1.Maximum = 31;
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
var counter = 0;
var dotsCounter = 0;
rtbScroll.Text = "";
int iValueSm = trackBar1.Value + 1; // +1 because we start counting from 0
for (int i = 1; i <= 32; i++)
{
if (counter > 0 && counter % 8 == 0)
{
// new octet
rtbScroll.AppendText(".");
dotsCounter++;
}
if (i > iValueSm)
{
// It is red
rtbScroll.AppendText("H");
rtbScroll.SelectionStart = (i - 1) + dotsCounter;
rtbScroll.SelectionLength = 1 ;
rtbScroll.SelectionColor = Color.Red;
}
else
{
rtbScroll.AppendText("N");
}
counter++;
}
}
Anytime you set the .Text() property, you RESET all formatting back to black and white.
Here is how I'd write it using SelectedText:
private void Form1_Load(object sender, EventArgs e)
{
updateRTB();
}
private void trackBarSmMask_ValueChanged(object sender, EventArgs e)
{
updateRTB();
}
private void trackBarSmMask_Scroll(object sender, EventArgs e)
{
updateRTB();
}
private void updateRTB()
{
rtbScroll.Text = "";
rtbScroll.SelectionStart = 0;
rtbScroll.SelectionLength = 0;
int iValueSm = trackBarSmMask.Value;
labelAmountNetID.Text = "/" + iValueSm.ToString();
for (int i = 1; i <= 32; i++)
{
rtbScroll.SelectionColor = (i <= iValueSm) ? Color.Blue : Color.Red;
rtbScroll.SelectedText = (i <= iValueSm) ? "N" : "H";
if (i % 8 == 0 && i != 32)
{
rtbScroll.SelectionColor = Color.Black;
rtbScroll.SelectedText = ".";
}
}
}
I found a code to get a different output, but it could be a hint for a solution.
public string GetCode(int number)
{
int start = (int)'A' - 1;
if (number <= 26) return ((char)(number + start)).ToString();
StringBuilder str = new StringBuilder();
int nxt = number;
List<char> chars = new List<char>();
while (nxt != 0) {
int rem = nxt % 26;
if (rem == 0) rem = 26;
chars.Add((char)(rem + start));
nxt = nxt / 26;
if (rem == 26) nxt = nxt - 1;
}
for (int i = chars.Count - 1; i >= 0; i--) {
str.Append((char)(chars[i]));
}
return str.ToString();
}
The output for this method is
A
B
C
(...)
Z
AA
AB
AC
(...)
AZ
AAA
(...)
I would like to achieve slightly different output, stated in the title. What would be the most efficient solution for it?
Rather than get code for each number it is more efficient just to count. So my code is counting to 52 (a-zA-Z) and then ripple and adding one to next 52 Place (just like decimal counting where you get to 10 and then add one to next place). See code below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
new RipleCount52(10000);
}
}
public class RipleCount52
{
//places are a number from 0 t0 51 indicating each of the 52 charaters
//the least significant place is index 0
//when printing character the order has to be reversed so most significant place gets printed first.
public List<int> places = new List<int>();
public RipleCount52(int maxNumber)
{
int count = 0;
places.Add(count);
for (int i = 0; i < maxNumber; i++)
{
string output = string.Join("",places.Reverse<int>().Select(x => (x < 26) ? (char)((int)'a' + x) : (char)((int)'A' + x - 26)));
Console.WriteLine(output);
places[0] += 1;
//riple after all 52 letter are printed
if (count++ == 51)
{
Ripple();
count = 0;
}
}
}
private void Ripple()
{
//loop until no ripple is required
for (int i = 0; i < places.Count(); i++)
{
if (places[i] == 52)
{
//all places rippled a new place needs to be added
if (i == places.Count - 1)
{
places[i] = 0;
places.Insert(0, 0);
break;
}
}
else
{
//no more ripples are required so exit
places[i] += 1;
break;
}
places[i] = 0;
}
}
}
}
I want to send a serial data from Arduino to an app using C# IDE Visual Studio. I will send 40 character with 9600 baudrate. The connection between Arduino in C# is good, the problem is when I send the data to C# using ReadLine command. I don't get the whole data, and always some first data loss, for an example if I send 123456789, in C#, it reads just 456789 or 89 or 3456789.
#define TC1 A0
#define TC2 A1
#define TC3 A2
#define TC4 A3
#define TC5 A4
#define TC6 A5
#define TC7 A6
#define TC8 A7
//#define TC9 A8
//#define TC10 A9
float K1 = 1;
float K2 = 1;
float K3 = 1;
float K4 = 1;
float K5 = 1;
float K6 = 1;
float K7 = 1;
float K8 = 1;
float K9 = 1;
float K10 = 1;
int n = 10;
int temp[10];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int x = 100;
temp[0]=analogRead(TC1)*K1*x*5/1023;
temp[1]=analogRead(TC2)*K2*x*5/1023;
temp[2]=analogRead(TC3)*K3*x*5/1023;
temp[3]=analogRead(TC4)*K4*x*5/1023;
temp[4]=analogRead(TC5)*K5*x*5/1023;
temp[5]=analogRead(TC6)*K6*x*5/1023;
temp[6]=analogRead(TC7)*K7*x*5/1023;
temp[7]=analogRead(TC8)*K8*x*5/1023;
temp[8]=analogRead(TC8)/5*200*K9;
temp[9]=analogRead(TC8)/5*200*K10;
// temp[0] = 1101;
// temp[1] = 2327;
// temp[2] = 114;
// temp[3] = 6753;
// temp[4] = 50;
// temp[5] = 1;
// temp[6] = 24;
// temp[7] = 123;
// temp[8] = 1269;
// temp[9] = 3;
for (int i = 0; i <= n - 1; i++) {
char buff[] = {'0', '0', '0', '0'};
int length_temp = String(temp[i]).length();
for (int j = length_temp - 1; j >= 0; j--) {
buff[j] = String(temp[i])[length_temp - j - 1];
}
for (int j = 0; j <= 3; j++) {
Serial.write(buff[3 - j]);
}
}
Serial.write('\n');
}
That is my Arduino code, and here the entire my C# code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO.Ports;
using System.Windows.Forms;
namespace Display_data
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void start_Click(object sender, EventArgs e)
{
}
private void stop_Click(object sender, EventArgs e)
{
//myport.Close();
//textbox.Text = "Koneksi diputus!";
}
private void makefile_Click(object sender, EventArgs e)
{
//String simpan = #"C:\"; //Alamat penyimpanan
//string nama_file = "Data.txt";
//System.IO.File.WriteAllText(simpan + nama_file, (ch1.Text+','+ ch2.Text + ',' + ch3.Text + ',' + ch4.Text + ',' + ch5.Text + ',' + ch6.Text + ',' + ch7.Text + ',' + ch8.Text + ',' + ch9.Text + ',' + ch10.Text ));
//MessageBox.Show("Data telah tersimpan di " + simpan + nama_file);
//string nama_gambar = "Data.png";
//this.grafik.SaveImage(simpan + nama_gambar, System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Png);
//MessageBox.Show("Gambar telah tersimpan di " + simpan + nama_gambar);
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void Port_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void connect_Click(object sender, EventArgs e)
{
myport = new SerialPort();
myport.BaudRate = 9600;
myport.PortName = Port.Text;
myport.DataReceived += receive;
try
{
myport.Open();
textbox.Text = "Connected";
}
catch (Exception)
{
textbox.Text = "Connection Failed!";
}
}
int j;
void receive(object sender, SerialDataReceivedEventArgs e)
{
string data = myport.ReadLine();
int CHa;
int CHb;
int CHc;
int CHd;
int CHe;
int CHf;
int CHg;
int CHh;
int CHi;
int CHj;
j++;
int delay = 500;
CHa = Int32.Parse(data.Substring(0, 4));
CHb = Int32.Parse(data.Substring(4, 4));
CHc = Int32.Parse(data.Substring(8, 4));
CHd = Int32.Parse(data.Substring(12, 4));
CHe = Int32.Parse(data.Substring(16, 4));
CHf = Int32.Parse(data.Substring(20, 4));
CHg = Int32.Parse(data.Substring(24, 4));
CHh = Int32.Parse(data.Substring(28, 4));
CHi = Int32.Parse(data.Substring(32, 4));
CHj = Int32.Parse(data.Substring(36, 4));
//ch1.Text = data.Substring(0, 4);
//ch2.Text = data.Substring(4, 4);
//ch3.Text = data.Substring(8, 4);
//ch4.Text = data.Substring(12, 4);
//ch5.Text = data.Substring(16, 4);
//ch6.Text = data.Substring(20, 4);
//ch7.Text = data.Substring(24, 4);
//ch8.Text = data.Substring(28, 4);
//ch9.Text = data.Substring(32, 4);
//ch10.Text = data.Substring(36, 4);
ch1.Text = CHa.ToString();
ch2.Text = CHb.ToString();
ch3.Text = CHc.ToString();
ch4.Text = CHd.ToString();
ch5.Text = CHe.ToString();
ch6.Text = CHf.ToString();
ch7.Text = CHg.ToString();
ch8.Text = CHh.ToString();
ch9.Text = CHi.ToString();
ch10.Text = CHj.ToString();
this.grafik.Series["Ch 1"].Points.AddXY(j * delay, CHa);
this.grafik.Series["Ch 2"].Points.AddXY(j * delay, CHb);
this.grafik.Series["Ch 3"].Points.AddXY(j * delay, CHc);
this.grafik.Series["Ch 4"].Points.AddXY(j * delay, CHd);
this.grafik.Series["Ch 5"].Points.AddXY(j * delay, CHe);
this.grafik.Series["Ch 6"].Points.AddXY(j * delay, CHf);
this.grafik.Series["Ch 7"].Points.AddXY(j * delay, CHg);
this.grafik.Series["Ch 8"].Points.AddXY(j * delay, CHh);
this.grafik.Series["Ch 9"].Points.AddXY(j * delay, CHi);
this.grafik.Series["Ch 10"].Points.AddXY(j * delay, CHj);
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label11_Click(object sender, EventArgs e)
{
}
}
}
So what is the problem? Do I need to latch the open port command?
Ok I don't quite know but if you write '\n' to the Serial port as line ending and then use ReadLine in c# (I think you use windows?) it caused problems for me. I used my own "Line ending cahr". Just use something like '!' and then always read only one char and compare it to '!'.
pseudocode:
string msg = ""
char read = readchar()
if(read == '!')
//stop reading
else
//add char to string
msg += read
Solved guys, my problem is the first line of the serial data from arduino is not exactly like what i'm trying to send, but for the second line and after that it's normal just like what i print to serial. i still don't know why but my method is just skip my first line incoming data
I am currently writing a program dealing with Cartesian Product. I have figured out the first part of inputting two numbers and getting the set for each number inputted. But what i need is the final product of both numbers.
In other words I am looking for my product to look something like this:
{ (1,1), (1,2), (1,3), ... }
Here is my code for right now with the last part of where I need help.
private void btnCal_Click(object sender, EventArgs e)
{
int iN, iM, i, j;
string strOut1, strOut2, strOut;
bool bN, bM;
bN = int.TryParse(txtN.Text, out iN);
bM = int.TryParse(txtM.Text, out iM);
if (bN && bM && iM > 0 && iM > 0)
{
strOut1 = "{1";
for (i = 2; i <= iM; i++)
strOut1 += "," + i;
txtFirst.Text = strOut1 + "}";
strOut2 = "{1";
for (j = 2; j <= iN; j++)
strOut2 += "," + j;
txtSecond.Text = strOut2 + "}";
}
//HERE IS WHERE THE PRODUCT CODE WILL BE AT
if (bN && bM && iM > 0 && iM > 0)
{
for (i = 2; i <= iM; i++)
for (j = 2; j <= iN; j++)
strOut = ("strOut1");
txtProduct.Text = strOut + " }";
}
else
txtProduct.Text = "Please enter valid number.";
}
With LINQ, all things are possible:
using System;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCal_Click(object sender, EventArgs e)
{
var tuples = from m in Enumerable.Range(1, int.Parse(txtM.Text))
from n in Enumerable.Range(1, int.Parse(txtN.Text))
select Tuple.Create(m, n);
txtProduct.Text = "{" + String.Join(",", tuples) + "}";
}
}
}
I'm working on visual C#
to calculate the word error rate
I have one textbox for the refrence which is the correct sentance
and one for the hypothesis which is wrong one.
in order to calculate WER I need to calculate :
substitution : the word that has been changed which was my first question
Insert : the words that had been inserted in the sentence
Deleted: the words that had been deleted from the original sentence
For EX:
refrence: This is a NPL program.
hypothesis: it is an NPL cool.
it: substitution
is: correct
an :substitution
NPL:correct
program: deleted
cool: inserted
I tried the algorithm that dasblinkenlight proposed ( thank you so much by the way )
I worked but there is a runtime error I couldn't figure it out, in line
int x= Compute(buffer[j], buffer_ref[i]);
Index was outside the bounds of the array.
and here is my code :
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
{
string [] hyp = new string[20];
string [] refrence = new string[20];
string [] Anser= new string[20];
string[] buffer = new string[20];
string[] buffer_ref = new string[20];
int count = 0; // number of words
string ref2=" " ;
string hyp2 = " ";
string Anser2 = " ";
string buffer2 = " ";
int corecct_c=0;
int corecct_d = 0;
int corecct_i = 0;
//====================================================================
public Form1()
{
InitializeComponent();
for (int i = 0; i <= 19; ++i)
{
hyp[i] = null;
buffer[i] = null;
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
refrence = this.textBox2.Text.Split(' ');
buffer_ref = this.textBox2.Text.Split(' ');
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
hyp = this.textBox1.Text.Split(' ');
buffer = this.textBox1.Text.Split(' ');
//hyp = this.textBox1.Text;
// fname1.Add(this.textBox1.Text);
}
public void correct(string[] R)
{
for (int i = 0; (i <= 19) && (R[i] != "."); ++i)
{
if (buffer[i] == refrence[i])
{ buffer[i] = "0";
buffer_ref[i] = "0";
corecct_c = corecct_c + 1;
Anser[i] = "C";
}
}
}
// function that compute 2 strings
public static int Compute(string s, string t)
{
int n = s.Length;
int m = t.Length;
int[,] d = new int[n + 1, m + 1];
// Step 1
if (n == 0)
{
return m;
}
if (m == 0)
{
return n;
}
// Step 2
for (int i = 0; i <= n; d[i, 0] = i++)
{
}
for (int j = 0; j <= m; d[0, j] = j++)
{
}
// Step 3
for (int i = 1; i <= n; i++)
{
//Step 4
for (int j = 1; j <= m; j++)
{
// Step 5
int cost = (t[j - 1] == s[i - 1]) ? 0 : 1;
// Step 6
d[i, j] = Math.Min(
Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1),
d[i - 1, j - 1] + cost);
}
}
// Step 7
return d[n, m];
}
public void sub(){
for (int j = 0;j<=19;j++)
{
if (buffer[j].IndexOf("0") != -1)
{
for (int i = 0; i <= 19; i++)
{
if (buffer_ref[j].IndexOf("0") != -1)
{
int x= Compute(buffer[j], buffer_ref[i]);
if (x > 3)
{
buffer[j] = "0";
Anser[j] = "S";
}
}//end if
}
}//end if
}//end for
}// end fun
private void button1_Click(object sender, EventArgs e)
{
correct(refrence);
sub();
for (int i = 0; (i <= 19) && (refrence[i] != "."); ++i)
{
//loop intialize
ref2 = ref2 + " " + refrence[i];
hyp2 = hyp2 + " " + hyp[i];
Anser2 = Anser2 + " " + Anser[i];
buffer2 = buffer2 + " " + buffer[i];
count++;
}
listBox1.Items.Add(" Refrence :" + ref2);
listBox1.Items.Add(" HYp :" + hyp2);
listBox1.Items.Add(" Anser:" + Anser2);
listBox1.Items.Add(" buffer:" + buffer2);
listBox1.Items.Add(count);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
can you help me please ?
There is a built-in way to test if two lines are identical, but there is no built-in way to tell if two lines are similar. You need to implement an algorithm that measures string similarity, such as the Levenshtein Distance - a very common Edit Distance algorithm. Lines with small edit distance can be declared similar depending on some threshold specific to your requirements.
You'll need to use an algorithm that compares the "distance" between two strings:
The closeness of a match is measured in terms of the number of
primitive operations necessary to convert the string into an exact
match. This number is called the edit distance between the string and
the pattern. The usual primitive operations are:
insertion: cot → coat
deletion: coat → cot
substitution: coat → cost