473,545 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

50 New Member
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 1931
vanc
211 Recognized Expert New Member
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
bmerlover
50 New Member
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
bmerlover
50 New Member
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
bmerlover
50 New Member
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
11130
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
13050
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 server is on one line (\r\n at end) and is formed as - each of which is seperated by a space. Arguments with spaces in them are enclosed in...
13
3945
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 well with this below shown code (code placed in a buttonclick event after selecting the file in a normal OpenFileDialog): ...
3
7504
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 ItemPrice As Integer Private PluValue As Integer
6
8013
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
4086
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 that my second repeater has the following error, System.NullReferenceException: Object reference not set to an instance of an object. When I put a...
111
19934
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 -- ------------------------------------- http://www.riscossione.info/
5
1666
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 (me.childname.column(0)," & _ "me.teacher.column(0), me.kidID, " & _ "#" & Me.formdate & "#);"
8
2051
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 message. I can't seem to find where I'm going wrong. Here's the code: Setting Cookie and Form Page: <html><head><title>Problem3</title> <script...
0
7467
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.