Results 1 to 3 of 3

Thread: Easy one: string/char comparison

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2004
    Posts
    21

    Easy one: string/char comparison

    I need to compare two character array elements to see if they have the same value, but using a text compare rather than a binary compare of the scan codes. I want to do what VB's Option Compare Text does rather than Option Compare Binary, which is what I am seeing as a result of this comparison:

    Code:
    if ((s[i]!=s[j]) || (s[i].Equals(s[j])))
    For instance if the ith element contains the character P and the jth element contains p, then they must be equal and this if condition must return true.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    PHP Code:
    string str1 System.Text.Encoding.Default.GetString(arr1).ToLower();
    string str2 System.Text.Encoding.Default.GetString(arr2).ToLower();

    int intResult string.Compare(str1str2); 

  3. #3
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159
    Hi,

    It looks to me like your first condition is testing if the entire array of "s" is equal to just one element.... is that really what you want to do?

    I think all you need to say is:

    Code:
    if (s[i].Equals(s[j])) {
    }
    So if the values of element i equals element j then you will return true.

    Hope this helps?
    DJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width