Strings manipulation issues

I am having issues with string assignment and manipulation issues. My environment is:

  1. Mostly class based.
  2. Arduino Ethernet board
  3. Using the latest version of IDE(1.6)
  4. Developing using VisualMicro
void RelayDevice::update(Controller<PowerDevice, SwitchEthernet> *control)
{
	Serial.println("Device update called");
	Serial.println(control->htmlPage);
	String rawCommand = String(control->htmlPage);
	Serial.println(rawCommand);
	int ind1 = rawCommand.indexOf("?");
	int ind2 = rawCommand.indexOf("HTTP/1.1");
	Serial.print("Index1: "); Serial.println(ind1);
	Serial.print("Index2: "); Serial.println(ind2);
	String command = rawCommand.substring(ind1, ind2);
	Serial.print("Command: "); Serial.println(command);
	command->trim();
	control->returnPage = "<?xml version=\"1.0\" encoding=\"utf-8\"?> <datavalues><relay1state>1</relay1state></datavalues>";
}

Here’s the output: [Comments]
Device update called Function is called properly by event controller.
GET /?get HTTP/1.1 HtmlPage is set properly
Should be assigned and same as htmlPage
Index1: -1 Should have value 5
Index2: -1 Should have value 10
Command: Should have value get
Sending data Event manager calls TcpClient flush.

I dont understand why the control->htmlPage is not getting assigned to rawCommand. Even if i directly use the control->htmlPage the indexOf doesnt work.

Maybe I have forgotten C++ or its just one of those small programming bugs that give you nightmares. Please help… need to develop this urgently.

What does Serial.println(rawCommand); return?
Which arduino board are you using? The String object takes up quite a bit of memory so people tench to use char strings.

mistergreen:
What does Serial.println(rawCommand); return?
Which arduino board are you using? The String object takes up quite a bit of memory so people tench to use char strings.

I am using the arduino ethernet board w/o poe. Serial.println(rawCommand); is outputting a blank line to serial monitor. How would i use char array here. Wont it require a lot of work to manipulate ? I basically need to read the command and set the relay status

I dont understand why the control->htmlPage is not getting assigned to rawCommand.

The most likely reason is because the allocation of memory failed, because htmlPage is too big.

I basically need to read the command and set the relay status

Why do you think that you will find ?anything on the outgoing html page? If that is not what htmlPage is, why does it have such a piss-poor name?

rohanbhatia1987:
Serial.println(rawCommand); is outputting a blank line to serial monitor.

That answers you problem. I'm assuming your htmlPage contains the header not an actual HTML page.

To work with char strings, you pass the reference. Easy-peesy .
And you have a handful of C functions you can use <cstring> (string.h) - C++ Reference