hai everyone....
i am doing a project in c sharp, ie LEXICAL ANALYZER. so i want some help, i want to read each line from richtextbox and store into an array? and also check matching two array? plz help
Richtextbox
19 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Sep 28, 2010, 1:01 AM EDT
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Sep 28, 2010, 2:03 AM EDT
You can write this way:
string[] keyword ={ "int", "float" };
private void button1_Click(object sender, EventArgs e)
{
CteateArray();
}
private void CteateArray()
{
string[] str = new string[richTextBox1.Lines.Length];
for (int i = 0; i <= richTextBox1.Lines.Length - 1; i++)
{
str[i] = richTextBox1.Lines[i].ToString();
if (Match(str[i]))
{
// write Code for write string in file
}
}
}
private Boolean Match(string str)
{
Boolean Find = false;
int j;
int Index = 0;
for (j = 0; j < keyword.Length; j++)
{
Index = keyword[j].IndexOf(str);
if (Index >= 0)
Find = true;
}
return Find;
}
thanks
Suthish NairRank #93 · 22.6K pointsPosted Sep 28, 2010, 12:07 AM EDT
Can you explain in detail about your project.
Its a Web or Windows project.
you can refer WPF RichTextBox:
http://www.c-sharpcorner.com/UploadFile/mahesh/WPFRichTextBox09072008194855PM/WPFRichTextBox.aspx
vishnu krishnan66 pointsPosted Sep 28, 2010, 12:28 AM EDT
it is a windows project..
i hope u knw the lexical analyzer, am plan to do this, just like, load the program into a richtextbox, then split program with space and comma, and identify all the keywords, identifiers store in a file.
so now i load the splitted program into a richtextbox, i think take each line from the richtextbox and checking with an array, which contains stored all the keywords, if find any keyword in that array, write that into a file.
vishnu krishnan66 pointsPosted Sep 28, 2010, 12:34 AM EDT
it is a windows project..
i hope u knw the lexical analyzer, am plan to do this, just like, load the program into a richtextbox, then split program with space and comma, and identify all the keywords, identifiers store in a file.
so now i load the splitted program into a richtextbox, i think take each line from the richtextbox and checking with an array, which contains stored all the keywords, if find any keyword in that array, write that into a file.
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Sep 28, 2010, 12:35 AM EDT
hello Vishnu
try this code for saving each line of richtextbox in array:
string[] str = new string[richTextBox1.Lines.Length];
for (int i = 0; i <= richTextBox1.Lines.Length - 1; i++)
{
str[i] = richTextBox1.Lines[i].ToString();
}
thanks
please mark as answer if it helps
vishnu krishnan66 pointsPosted Sep 28, 2010, 1:03 AM EDT
string[] keyword ={ "int", "float" };
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Sep 28, 2010, 1:19 AM EDT
string[] keyword ={ "int", "float" };
int j;
int Index = 0;
for (j = 0; j < keyword.Length; keyword++)
{
Index = keyword[j].IndexOf(str[i]);
if (Index >= 0)
break; // Find string in array
}
thanks
vishnu krishnan66 pointsPosted Sep 28, 2010, 1:29 AM EDT
how to print the matching keyword or how to write that into a file.
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Sep 28, 2010, 1:32 AM EDT
i give you maintained code....
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Sep 28, 2010, 1:41 AM EDT
string[] keyword ={ "int", "float" };
private void CteateArray()
{
string[] str = new string[richTextBox1.Lines.Length];
for (int i = 0; i <= richTextBox1.Lines.Length - 1; i++)
{
str[i] = richTextBox1.Lines[i].ToString();
if (Match(str[i]))
{
// write Code for write string in file
}
}
}
private Boolean Match(string str)
{
Boolean Find = false;
int j;
int Index = 0;
for (j = 0; j < keyword.Length; j++)
{
Index = keyword[j].IndexOf(str);
if (Index >= 0)
Find = true;
}
return Find;
}
thanks
vishnu krishnan66 pointsPosted Sep 28, 2010, 2:00 AM EDT
{
string[] keyword ={ "int", "float" };
private void CteateArray()
{
string[] str = new string[richTextBox1.Lines.Length];
for (int i = 0; i <= richTextBox1.Lines.Length - 1; i++)
{
str[i] = richTextBox1.Lines[i].ToString();
if (Match(str[i]))
{
// write Code for write string in file
}
}
}
private Boolean Match(string str)
{
Boolean Find = false;
int j;
int Index = 0;
for (j = 0; j < keyword.Length; j++)
{
Index = keyword[j].IndexOf(str);
if (Index >= 0)
Find = true;
}
return Find;
}
}
sir can i write this way, in a button? i will give some error in the string[] keyword ={ "int", "float" }; ?
vishnu krishnan66 pointsPosted Sep 28, 2010, 2:08 AM EDT
sorry sir that was my mistake, sir i need some help from u
how the return write into a file? or how that write into the same richtextbox?
plz help
vishnu krishnan66 pointsPosted Sep 28, 2010, 2:15 AM EDT
str[i] = richTextBox1.Lines[i].ToString();
if (Match(str[i]))
{
//here
}
vishnu krishnan66 pointsPosted Sep 28, 2010, 2:28 AM EDT
str[i] = richTextBox1.Lines[i].ToString();
if (Match(str[i]))
{
TextWriter tw = new StreamWriter("help.txt");
tw.WriteLine(str);
tw.Close();
}
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Sep 28, 2010, 2:37 AM EDT
private void CteateArray()
{
string[] str = new string[richTextBox1.Lines.Length];
TextWriter tw = new StreamWriter("C:\\help.txt");
for (int i = 0; i <= richTextBox1.Lines.Length - 1; i++)
{
str[i] = richTextBox1.Lines[i].ToString();
if (Match(str[i]))
{
tw.WriteLine(str[i].ToString());
// write Code for write string in file
}
}
tw.Close();
}
thanks
vishnu krishnan66 pointsPosted Sep 28, 2010, 2:45 AM EDT
sir i am getting the text file contain only "int"????....
vishnu krishnan66 pointsPosted Sep 28, 2010, 3:01 AM EDT
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Sep 29, 2010, 2:13 AM EDT
thanks
2 short replies
vishnu krishnan66 pointsPosted Sep 28, 2010, 1:35 AM EDT
Hirendra SisodiyaRank #256 · 9.8K pointsPosted Sep 28, 2010, 2:12 AM EDT