Thread: compare two strings

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    65

    compare two strings

    whats the best way for comparing 2 string to check if they are equal
    i know that 1 ways is with strcmp(string1,string2) but i want to compare them, first with upper and lower letters make them different and second without upper and lower sensitivity
    1st: "test Test" == the same
    2st:"test Test"== different
    strcmp always check the upper and lower option

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    120
    Write your own function in which you will test each pair of characters in both strings. You can use one of these functions from ctype.h :
    isupper()
    islower()
    toupper()
    tolower()
    Last edited by DRK; 02-07-2012 at 08:54 AM.

  3. #3
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    You can also compare each character with ASCII values to determine upper and lower.
    ASCII Code - The extended ASCII table

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    58
    You could also look into using
    strcasecmp, strncasecmp - case-insensitive string comparisons

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare strings
    By jamal in forum C Programming
    Replies: 6
    Last Post: 11-27-2011, 08:09 PM
  2. How can I compare strings?
    By errigour in forum C Programming
    Replies: 9
    Last Post: 11-16-2010, 05:54 PM
  3. Compare Two Strings?
    By Paul22000 in forum C++ Programming
    Replies: 9
    Last Post: 05-24-2008, 05:09 PM
  4. Trying to compare to strings...
    By imortal in forum C++ Programming
    Replies: 9
    Last Post: 05-16-2003, 12:27 PM
  5. how do i compare strings
    By bart in forum C++ Programming
    Replies: 17
    Last Post: 08-30-2001, 09:17 PM