How to check whether the data has two,three and four values in it separated by (,) and eliminate it?

How to check whether the data has two, three and four values in it separated by( (,) and eliminated it?

For example when I retrieve a primary key from the database.  Sometime, it has
Individual value --> (1234)
two values --> (1234,1234)
three value --> (1234,1234,1234)

Four values --> (1234,1234,1234,1234)

well, I am supposed to proceed with the only individual value and eliminate the rest of the things?

Can somebody please help how to develop the logic to write the function?

Thanks everyone !
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
That looks weird.  (Check the table definition to confirm the key are string values).  How do you retrieve that primary key.
developer2012Author Commented:
Yes, those are string values. I retrieve those values by querying the data.

For example

Select primarykey from database where columnname = columnname;

and It returns values like;


I mean sometimes it may have the single value too, sometime double values

but I am suppose to use only one string value. i.e. something like the format of '1234' and ignore the rest.

AndyAinscowFreelance programmer / ConsultantCommented:
string s = "1234,";
            if(s.IndexOf(',') == (s.Length - 1))//true for this string
                //do your stuff here for the single 'number'

string s = "1234,1234,";
            if(s.IndexOf(',') == (s.Length - 1))//false for this string
                //do your stuff here for the single 'number'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
developer2012Author Commented:
Thanks Andy,

I will implement the function and update here.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.