473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Reading inside the quotations in a String (Visual C++)

Hi, I need to read a script file and change the text on the buttons I set. I have the psuedocode in my head, but I'm having trouble putting that into code. I figured out how to seperate B1 from T1 and etc. from each other. From there I haven't tried yet but I'm pretty sure I can change the text on the buttons. My question is how can I read what is inside the quotations and save that into a string. Well I can save that into a string as long as I can read it. I use the StartsWith() to find out which button the quotation belongs to and since I'm reading the richTextBox line by line, I can change the text button names inside the while loop. I just need to read inside the quotations. I'm using Visual Studio .NET 2003 C++.

example script file:

#comment
B1 = "ABC"
T1 = "DEF"
etc,

I'm currently trying many different options but here is what I have so far. My code runs fine but it is incomplete.

Expand|Select|Wrap|Line Numbers
  1.  
  2.             scriptString = richTextBox1->Text;
  3.             scriptReader = new StringReader(scriptString);
  4.  
  5.             int nextChar = 0;
  6.             String* line = "";
  7.  
  8.  
  9.  
  10.             //iterate over the string using the StringReader, printing each line. 
  11.             while(nextChar >= 0)
  12.             {    
  13.                 //reading line by line    
  14.                 line = scriptReader->ReadLine();////
  15.                 //making sure it read correctly
  16.  
  17.                 //richTextBox1->AppendText(str->StartsWith(“B1”);
  18.                 //line->Replace(L'B',L'A');
  19.                 richTextBox1->AppendText(line);
  20.                 richTextBox1->AppendText("\n");
  21.  
  22.                 //check if there's any more lines
  23.                 nextChar = scriptReader->Peek();
  24.  
  25.             }
  26.  
  27.  
  28.  
  29.  
Thanks in advance.
Aug 1 '07 #1
4 1922
vanc
211 Expert 100+
I may not fully understand your problem but if you want to read string inside quotation then Split it by quotation as separator.
e.g.: B1 = "ABC" .Split('"') --> an array of string that contain B1 = , ABC, . So the second string in that array is its name ABC.

Is it what you are trying to do?

cheers.
Aug 1 '07 #2
I'm assuming you're suggesting to split each line into two parts and the first part is the button that it's assigned to, and the second is the text I need to replace it with.

Thanks vanc, I'm going to try your suggestion if I run into problems hours later, I will post another question.
Aug 2 '07 #3
Here is what I got so far. It works as long as there aren't too many spaces in between T1 = (top). Although I still have the same problem, I still can't make it parse out quotations.

When I place a quotation in delimStr
(i.e. String* delimStr = S" = ( ) ' : " \0 [ ] { } - ";), (3 quotations inside, I will bold inside one) I get these two errors.

error C2015: too many characters in constant
error C2001: newline in constant

I've done a lot of reading and debugging. It seems the best approach would be something of this nature wchar_t temp = L'"'; but I need to save it as a character array and I get errors from that as well. I've tried many different approaches of character arrays and tryed saving it to String. Still can't figure the quotations out. I need help with this, I need it to parse out the quotations and read inside of it.

Current example of code works. It takes a script file and changes the buttons. As long as the script file is saved in RTF format.

T1 = (top)
T2 = (bottom)
etc.


Expand|Select|Wrap|Line Numbers
  1.  
  2.         scriptString = richTextBox1->Text;
  3.             scriptReader = new StringReader(scriptString);
  4.  
  5.             String* delimStr = S" = ( ) ' : \0 [ ] { } - ";
  6.             Char delimiter[] = delimStr->ToCharArray();
  7.             String* split[] = 0;
  8.             int nextChar = 0;
  9.             String* line = "";
  10.             String* str;
  11.             //String* str2;// = str1->Trim(delim->ToCharArray());
  12.             //str2 = str2->ToString(str1->Trim(delim->ToCharArray()));
  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.                 //making sure it read correctly
  20.                 line = line->TrimStart(NULL);
  21.                 for (int x = 0; x < line->Length; x++) 
  22.                 {    //line = line->TrimEnd(NULL);
  23.                     split = line->Split(delimiter, x);
  24.                     richTextBox1->AppendText(S"\ncount = {0, 2} .............."); 
  25.                     richTextBox1->AppendText(__box(x)->ToString());
  26.                     IEnumerator* myEnum = split->GetEnumerator();
  27.  
  28.                     while (myEnum->MoveNext()) 
  29.                     {    //line = line->TrimStart(NULL);
  30.                         String* s = __try_cast<String*>(myEnum->Current);
  31.                         richTextBox1->AppendText(S" ");
  32.                         richTextBox1->AppendText("Last s: ");
  33.                         richTextBox1->AppendText(s);
  34.  
  35.                         //if (myEnum->MoveNext()) //save the last s (which is the name)
  36.                         if(myEnum->MoveNext() && s != NULL)
  37.                         {
  38.                             str = s;
  39.                         }
  40.                     }
  41.                 }
  42.  
  43.                 if(line->StartsWith("T1"))
  44.                 {
  45.                     top1->Text = str;
  46.                     defaultText(sender, e, top1);
  47.                 }
  48.                 else if(line->StartsWith("T2"))
  49.                 {
  50.                     top2->Text = str;
  51.                     defaultText(sender, e, top2);
  52.                 }
  53.  
  54.                 richTextBox1->AppendText("\nThis is the str: ");
  55.                 richTextBox1->AppendText(str);
  56.                 richTextBox1->AppendText("\n");
  57.                 //richTextBox1->AppendText(str->StartsWith(hello);
  58.                 //line->Replace(L'B',L'A');
  59.                 //richTextBox1->AppendText(str);
  60.                 richTextBox1->AppendText("\n");
  61.  
  62.                 //check if there's any more lines
  63.                 nextChar = scriptReader->Peek();
  64.  
  65.             }
  66.  
  67.  
Thanks in advance
Aug 3 '07 #4
I just discovered something if you put the quotation inside the delimStr with a backslash in front of it, it compiles fine.

Example:

String* delimStr = S" = ( ) ' \" : \0 [ ] { } - ";

It does parse out the quotations except there has to be a space between the word and the quotations such as:

Sample Script File:

T1 = " top "
T2 = "top"

In this example T1 works, but T2 doesn't work.

Does anyone know why and how to fix the problem? In the meantime I'm going to try and figure it out.

Thanks Again in Advance.
Aug 3 '07 #5

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

Similar topics

1
by: xmlguy | last post by:
PREVIOUS BACKGROUND POST: I am trying to reuse a Memory Stream for loading and transforming the xml it contains Basically I have defined following interfaces: Class Render {
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
13
by: mloichate | last post by:
I must read a very heavy-weight text plain file (usually .txt extension) )and replace a given character with another given character in all text inside the file. My application was working pretty...
3
by: Zahid | last post by:
Hi, I have declared an array holding a custom declared structure. The structure looks like this: Private Structure MnuDataFrmFile Public menuGroup As String Public ItemDesc As String Public...
6
by: Kondapanaidu | last post by:
Hi, I am using C#V1.1. How to add double quotations to a string. If I go with "\"" the back slash is going to be added to the assigned string. EX: string str="naidu" + "\"" + "GK" + "\"";
0
by: uncensored | last post by:
Hello everyone, I'm fairly new at .Net and I have a repeater inside a repeater problem. I will attach my code to this message but basically what I am able to tell when I run my page it tells me...
111
by: Tonio Cartonio | last post by:
I have to read characters from stdin and save them in a string. The problem is that I don't know how much characters will be read. Francesco -- ------------------------------------- ...
5
by: sparks | last post by:
I was using this to add a record to a table but the systax is messing me up. strSQL = "INSERT INTO TblChallengeRECESS ( childname, teacher, kidid, formdate) " & _ "VALUES...
8
by: LayneMitch via WebmasterKB.com | last post by:
I'm supposed to develop a page that asks info as form values and when you hit "submit" it takes you to a page that reads the values you entered into the first page and displays those values in a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.