Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Comments
Tharaka MTR 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 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

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!
 
Share this answer
 
Comments
Sandeep Mewara 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 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900