Search for a specific character : string search « string « C++ Tutorial






#include <iostream>
#include <cstring>

using namespace std;

int main() {

  const char *url = "server.com";
  const char *url2 = "Apache.org";
  const char *emailaddr = "Herb@server.com";

  const char *tld[] = { ".com", ".net", ".org" };

  const char *p;

  // Search for a specific character.
  p = strchr(emailaddr, '@');
  if(p) cout << "Site name of e-mail address is: " << p+1 << endl;

  return 0;
}








15.20.string search
15.20.1.Search a null-terminated string: determine if url and url2 contain .com, .net, or .org.
15.20.2.Search for a specific character
15.20.3.Search for any of a set of characters. In this case, find the first @ or period.
15.20.4.string search with custom comparison function