Click here to Skip to main content
11,490,266 members (34,891 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
for example i have a string like 1,2,3,4,1,2 then i need to check each value with other values in for loop if any two values are same in string den i need to provide an alert can any help me for the logic ...advance thanks

example:first split-ed value is "1" it should check with 2,3,4,1,2 den at some point 1=1 then i should not provide an alert after completing total loop den i need to provide an alert
Posted 20-Feb-13 7:16am
Comments
Tharaka MTR at 20-Feb-13 12:22pm
   
with regarding your input 1,2,3,4,1,2
do you want to give the output once all the loop completed?
that's mean finally you want to give the alert saying "there are some duplicate value exists for 1 and 2?
Is that you want or please elaborate your question more
Mounika Reddy at 20-Feb-13 12:31pm
   
yes i have some id's string like 1,2,3,4,1,2 after selecting i will submit my record at the of submission i need to compare all id if any two id are same den i need to show an alert as "1 and 2 are already exists"

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Steps:
1. Split the string using ',' as a separator
2. create a flag 'isCopy' and set it to false
3. Start a loop for values one by one
4. if you find a match, then set the flag isCopy as true and continue the loop, don't do anything
5. Once the loop is complete, check for the value of flag
6. if flag value is true, show the alert or else move on to next item.

Try out now!
  Permalink  
Comments
Sandeep Mewara at 20-Feb-13 12:57pm
   
Then what will you do? Please don't say 'copy-paste'! :)

I provided the needed help and steps/algo. Try out.
Sergey Alexandrovich Kryukov at 20-Feb-13 19:58pm
   
I would not agree with the vote of 3. I voted 5. The solution answers the question.
—SA
Sandeep Mewara at 20-Feb-13 22:44pm
   
Thanks SA.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 570
1 Andy Lanng 233
2 OriginalGriff 188
3 Sascha Lefèvre 170
4 Maciej Los 160
0 Sergey Alexandrovich Kryukov 9,713
1 OriginalGriff 8,475
2 Sascha Lefèvre 3,504
3 Maciej Los 3,106
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100