SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Issue with comparing strings

    I have a string like (12345; 5678). I need to compare this value with another string (63434; 33434). Need to compare each value seperated with ; with the values in the 2nd string. I know this can be done by passing into array. But can someone help me give me the correct code to do this

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    A quick example to show you how you can get each element.

    Code JavaScript:
    var str1 = "12345; 5678";
    var str2 = "63434; 33434";
    var arr1 = str1.split(";");
    var arr2 = str2.split(";");
    var str1a = arr1[0].trim();
    var str1b = arr1[1].trim();
    var str2a = arr2[0].trim();
    var str2b = arr2[1].trim();
    alert (str1a + ":" + str1b + " - " + str2a + ":" + str2b);
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks.. But i already got the answer. I wanted to compare each value of the 1st array with all the values in the other one. I did it using 2 for loops..


Bookmarks

Posting Permissions

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