By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

Quotations in RichTextBox

P: 50
I'm having trouble reading quotations inside the richTextBox when a file is opened on to it. I've tried a couple different methods, most of them didn't compile. I came across one that does compile and supposedly it's suppose to work but it doesn't in my case.

I tried this code to see if it would recognize the quotations. For testing purpose I wanted to see if it would start the string from the quotation.

Expand|Select|Wrap|Line Numbers
  1. str = str->Substring(line->IndexOf("\""));
  2. richTextBox1->AppendText(str);
  3.  
Another attempt was also for testing purposes. I tried to replace the quotation with a word just to see if it would recognize it. Both of these codes compile without errors, but none of these statements recognize it.

Expand|Select|Wrap|Line Numbers
  1.  
  2. str = str->Replace(S"\"",S"Fast ");
  3. richTextBox1->AppendText(str);
  4.  
  5.  
Note: ( ) denotes characters inside richTextBox

One thing that I did notice is when I open a RTF file into the richTextBox, it seems like all the characters match with each other, by this I mean when I open the RTF file into the richTextBox, let's say the RTF File had a content of ("Car"), so after the RTF file is opened, I see ("Car") on the richTextBox. Afterwards, I physically type ("Car") into the richTextBox next to ("Car") that was opened from the RTF. The word Car looks exactly the same for both input and file. In the richTextBox you would see ("Car" "Car"). On the otherhand, for quotations they appear different, depending on the font, the quotation i type into the richTextBox looks different from that was opened form the RTF file. I don't know if that helps but it's an observation.

Is there a way I can resolve this issue so that my code would recognize the quotations from the RTF file?
Aug 24 '07 #1
Share this Question
Share on Google+
1 Reply


P: 50
I found the solution. As long as you write the script file inside the program, then the quotations work. Here is the code that works.

Expand|Select|Wrap|Line Numbers
  1.  
  2.                         scriptString = richTextBox1->Text;
  3.             scriptReader = new StringReader(scriptString);
  4.  
  5.             String* delimStr = S" =\"):[]{}"; 
  6.             Char delimiter[] = delimStr->ToCharArray();
  7.             String* split[] = 0;
  8.             int nextChar = 0;
  9.             int whiteSpaceCount = 0;
  10.             String* line = "";
  11.             String* str;
  12.             String* space = S" ";
  13.  
  14.             //iterate over the string using the StringReader, printing each line. 
  15.             while(nextChar >= 0)
  16.             {    
  17.                 //reading line by line    
  18.                 line = scriptReader->ReadLine();
  19.                 //erase any whitespaces until you see the first character of the string
  20.                 line = line->TrimStart(NULL);
  21.  
  22.                 for (int x = 0; x <= line->Length; x++) 
  23.                 {
  24.                     split = line->Split(delimiter, x);                
  25. IEnumerator* myEnum = split->GetEnumerator();
  26.                     str = String::Join(space, split);
  27.  
  28.                     while (myEnum->MoveNext()) 
  29.                     {    
  30.                         String* s = __try_cast<String*>(myEnum->Current);
  31.                     }
  32.  
  33.                 }
  34.  
  35.                 str = str->Substring(line->IndexOf("\"") + 1); 
  36.  
  37.                 while(str->StartsWith(S" "))
  38.                 {
  39.                     whiteSpaceCount++;
  40.                     str = str->Substring(line->IndexOf("\"") + whiteSpaceCount);            
  41.                 }
  42.  
  43.                 whiteSpaceCount = 0; //reset the counter, this counter is for white spaces in between the first quotation and the first word inside the quotation just incase there is a space. 
  44.  
  45.  
  46.                 if(line->StartsWith("T1"))
  47.                 {
  48.                     top1->Text = str;
  49.                     defaultText(sender, e, top1);
  50.                 }
  51.  
  52.                 //check if there's any more lines
  53.                 nextChar = scriptReader->Peek();
  54.  
  55.  
  56.  
Aug 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.