Delate something in a string.

Hello, I wanted to build a network to i²c converter.

But the strings are too long so I wanted to make them smaller.

         int spacePosition = readString.indexOf('/');
          if (readString.charAt(spacePosition + 1) == '?') 
          {
            Wire.beginTransmission(4); // transmit to device #4
            char buffer[32];
            readString.toCharArray(buffer, 32);
            Wire.write(buffer);
            Serial.print(buffer);
            Wire.endTransmission();    // stop transmitting
           }

the strings are

GET /?lighton0 HTTP/1.1
GET /favicon.ico HTTP/1.1

I have successfully deleted the favicon string.
and the second string I wanted to reduce that only remains 'lighton0'

sorry for my bad english, but im a german :smiley:

can anyone help me ?
Thanks for answer.

Please post your whole program so that your question can be seen in the context in which it is asked.

i think the rest isn't interesting but here...

#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {192, 168, 0, 5 }; // ip in lan
EthernetServer server(80); //server port
String readString; 
void setup()
{
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.begin(9600); 
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  Wire.begin(); // join i2c bus (address optional for master)
}
void loop()
{
  EthernetClient client = server.available();
  if (client) 
  {
    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        if (readString.length() < 100) readString += c; 
        if (c == '\n') 
        {
          client.stop();
          int spacePosition = readString.indexOf('/');
          if (readString.charAt(spacePosition + 1) == '?') 
          {
            Wire.beginTransmission(4); // transmit to device #4
            char buffer[32];
            readString.toCharArray(buffer, 32);
            Wire.write(buffer);
            Serial.print(buffer);
            Wire.endTransmission();    // stop transmitting
           }
           readString="";
        }
      }
    }
  }
}
#include <Wire.h>
void setup()
{
  Wire.begin(4);              
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);           
}
void loop()
{
  delay(100);
}
void receiveEvent(int howMany)
{
  while(1 < Wire.available()) // loop through all but the last
  {
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

Can you give an example of a string that is too long and what you want to reduce it to ?

"GET /?lighton0 HTTP/1.1" is the tring but i just need "lighton0"

You are using the String class, despite the issues that it presents. The class has indexOf() and substring() methods. You can look up how to use them.

          int firstPosition = readString.indexOf('/');
          if (readString.charAt(firstPosition + 1) == '?')
          {
            int secountPosition = readString.indexOf(' ',firstPosition+2);
            tempString = readString.substring(firstPosition+2,secountPosition);
            Wire.beginTransmission(4); // transmit to device #4
            char buffer[32];
            tempString.toCharArray(buffer, 32);
            Wire.write(buffer);
            Serial.println(buffer);
            Wire.endTransmission();    // stop transmitting
           }

it work thank you :slight_smile:

          int firstPosition = readString.indexOf('/');
          if (readString.charAt(firstPosition + 1) == '?')
          {
            int secountPosition = readString.indexOf(' ',firstPosition+2);

Wouldn't slashPosition and spacePosition make more sense as the names?