0

In the string below, I want to split the string separated by "|" (which i can do)and would then like to compare the first part and the boolean part of each such string with the same parts of another string.

var str = "Jacobs21]2]0]Ronan]false|Tom]2]0]Joseph]true|Jacobs21]2]0]NAME$$ALL]false|";
  1. In the string above, Jacobs21]2]0]Ronan]false is one string and so on.
  2. I am more interested in the Jacobs21 part of this string and the boolean value appearing at its end which is "false" here.
  3. Now, I want to compare the first and the last part joined as a single string to form Jocobs21false and similarly, for the another string tomtrue and make a comparison and see if there are any similar matches?
4
  • 3
    what did you try so far? Commented Dec 10, 2013 at 9:30
  • 1
    split againg at ] and then Take the name from the arrays element at index 0 and the boolean of the element at index 3 Commented Dec 10, 2013 at 9:34
  • @Igle: thats what i have done in my answer below..!! and somebody down voted it..!! Commented Dec 10, 2013 at 9:37
  • That wasn't me, can't tell you why... Commented Dec 10, 2013 at 9:39

1 Answer 1

2
var detailsArray = str.split("|");
var res = [];
for (var i = 0; i < detailsArray.length - 1; i++) {
    finalArray = detailsArray[i].toString().split("]");
    var name = finalArray[0];
    var booleanString = finalArray[4];
    res[i] = name.concat(booleanString);
}
for (var j = 0; j < res.length - 1; j++) {
    if (res[i] == res[i + 1]) {
        //do your stuff
    }
}
Sign up to request clarification or add additional context in comments.

5 Comments

I almost want to down vote just cause so badly aligned but would have felt like a jerk.
@codefactor: there's something called not voting if you don't like it but don't hate it ;)
Anyway, I don't think it's the best idea to hard code your index variables.
Now my eyes do not hurt when I look at your answer.
@codefactor : thanks..for suggesting the edits..!! you are definitely right..!! Readability is very important..!!