Hello, I just have a question about how to find a substring when one has only a string and coordinates for where the data will be? For instance, a string "why,hello", and data that is at the coordinates 4 to 8.

strstr, I obviously cannot use directly, because I have no idea what the string I am searching for is named.

I could use a loop that begins at 4 (just as an example; it would be a variable) and goes until 8, recording each character in a new character array. However, I have previously done this often only to find out that strcat(), memcpy(), or some other predefined function was already made and could probably work better than my code. :o

You can use

substr()

function of string class

Of course. I hadn't seen that in the cplusplus.com reference for cstring. In fact, cplusplus.com has apparently no documentation for substr at all.... Ah well, thanks for the function.

Of course. I hadn't seen that in the cplusplus.com reference for cstring. In fact, cplusplus.com has apparently no documentation for substr at all.

substr() is not a function of cstring -- it is a method of c++ std::string class.

#include <string>

int main()
{
std::string newstr;
std::string str = "why,hello";

int pos = str.find(',');
if(pos > 0)
  mewstr = str.substr(pos+1);

return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.