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
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hirendra SisodiyaPosted Sep 28, 2010, 6:03 AM
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
Hirendra SisodiyaPosted Sep 28, 2010, 5:01 AM
Hirendra SisodiyaPosted Sep 29, 2010, 6:13 AM
thanks
vishnu krishnanPosted Sep 28, 2010, 7:01 AM
vishnu krishnanPosted Sep 28, 2010, 6:45 AM
sir i am getting the text file contain only "int"????....
Hirendra SisodiyaPosted Sep 28, 2010, 6:37 AM
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 krishnanPosted Sep 28, 2010, 6:28 AM
str[i] = richTextBox1.Lines[i].ToString();
if (Match(str[i]))
{
TextWriter tw = new StreamWriter("help.txt");
tw.WriteLine(str);
tw.Close();
}
vishnu krishnanPosted Sep 28, 2010, 6:15 AM
str[i] = richTextBox1.Lines[i].ToString();
if (Match(str[i]))
{
//here
}
Hirendra SisodiyaPosted Sep 28, 2010, 6:12 AM
vishnu krishnanPosted Sep 28, 2010, 6:08 AM
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 krishnanPosted Sep 28, 2010, 6:00 AM
{
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" }; ?
Hirendra SisodiyaPosted Sep 28, 2010, 5:41 AM
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 krishnanPosted Sep 28, 2010, 5:35 AM
Hirendra SisodiyaPosted Sep 28, 2010, 5:32 AM
i give you maintained code....
vishnu krishnanPosted Sep 28, 2010, 5:29 AM
how to print the matching keyword or how to write that into a file.
Hirendra SisodiyaPosted Sep 28, 2010, 5:19 AM
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 krishnanPosted Sep 28, 2010, 5:03 AM
string[] keyword ={ "int", "float" };
Hirendra SisodiyaPosted Sep 28, 2010, 4:35 AM
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 krishnanPosted Sep 28, 2010, 4:34 AM
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 krishnanPosted Sep 28, 2010, 4:28 AM
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.
Suthish NairPosted Sep 28, 2010, 4:07 AM
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