Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

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 !
0
developer2012
Asked:
developer2012
  • 2
  • 2
1 Solution
 
AndyAinscowCommented:
That looks weird.  (Check the table definition to confirm the key are string values).  How do you retrieve that primary key.
0
 
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;

1234,
1234,1234,
1234,1234,1234,
1234,1234,1234,1234,

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.

Thanks.
0
 
AndyAinscowCommented:
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'
            }
0
 
developer2012Author Commented:
Thanks Andy,

I will implement the function and update here.

Thanks,
D.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now