Thread: first characters in a string

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    10

    Exclamation first characters in a string

    can anyone tell me how i would detect if "http://" was the first part of a string?

    eg "http://example.com" would be detected however "example.com" would not

    thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The standard library is your friend. strstr


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    10
    yes, but what if they enter "exahttp://ple.com" http still their but was not detected first, how can i make it so it has to be first, any ideas?

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
    char a[] =  "exahttp://ple.com";
    char *s;
      s = strstr(a,"http");
      if(s == a) {                  // found it at first
        printf("got it!\n");
      } else {                           //( found it but not at first ) or not in a
       printf("No\n");
    }
    Last edited by Bayint Naung; 03-27-2011 at 07:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unable to compare string with 'getter' returned string.
    By Swerve in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2009, 05:56 PM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  4. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM