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

Posted on 2014-08-07
Last Modified: 2014-08-14
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 !
Question by:developer2012
    LVL 43

    Expert Comment

    That looks weird.  (Check the table definition to confirm the key are string values).  How do you retrieve that primary key.

    Author Comment

    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.

    LVL 43

    Accepted Solution

    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'

    Author Comment

    Thanks Andy,

    I will implement the function and update here.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now