Click here to Skip to main content
13,001,686 members (89,508 online)
Rate this:
Please Sign up or sign in to 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 20-Feb-13 6:16am
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

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

Solution 1

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!
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.
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2017
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