Skip to content

Richtextbox

vishnu krishnan

Asked Sep 27, 2010, 11:58 PM EDTSolved
Share
LinkedInX
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

19 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Hirendra Sisodiya
    ✓ Accepted answer0
    Do you want to compare str[i] in another array???
     
    0
  • Hirendra Sisodiya
    ✓ Accepted answer0
    No
    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
    0
  • 0
    thanku for respose,....

    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.
    0
  • 0
    thanku for respose,....

    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.
    0
  • Hirendra Sisodiya
    0
     
    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
    0
  • 0
    yes, i want to comapre with another array, which i stored the kwywords;

    string[] keyword ={ "int", "float" };
    0
  • Hirendra Sisodiya
    0
    check this
    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
     
    0
  • 0
    thanku....
    how to print the matching keyword or how to write that into a file.
    0
  • Hirendra Sisodiya
    0
    wait....
    i give you maintained code....
    0
  • Hirendra Sisodiya
    0
    check this:
    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
    0
  • 0
     private void button1_Click(object sender, EventArgs e)
            {
                  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" };    ?
    0
  • 0
    thnks,
    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
    0
  • 0
    textfile format, or sir can u write that matched string into the richtextbox.


     str[i] = richTextBox1.Lines[i].ToString();
                    if (Match(str[i]))
                    {
                       
                                  //here

                    }
    0
  • 0
    sir i update the code for writing into file but that contain only System.string[];

    str[i] = richTextBox1.Lines[i].ToString();
                    if (Match(str[i]))
                    {
                        TextWriter tw = new StreamWriter("help.txt");

                       
                        tw.WriteLine(str);
                        tw.Close();

                    }
    0
  • Hirendra Sisodiya
    0
    modify this code like this:
     
    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
    0
  • 0
    thanks..

    sir  i am getting the text file contain only "int"????....
    0
  • 0
    sir have any way to get that all matched string
    0
  • Hirendra Sisodiya
    0
    above code write all matched string..check again..
    thanks
    0
  • 2 short replies
    • Hirendra Sisodiya
      0
      which type of file format??
       
      0