Click here to Skip to main content
14,691,021 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I have the column called Codes and the data will return from db like this
I need to split this in class and assign to another variables as i need to display these rows in excel sheet..

Can you please help me to fix this...


What I have tried:


<pre>public string codes { get; set; }

public string codes_format
     get {
       return values
        string[] values = _codes.Split(',');
       for (int i = 0; i < values.Length; i++)
         values[i] = values[i].Trim();

like codes_format1, codes_format2, ... codes_format8..
Updated 7-May-20 11:10am
F-ES Sitecore 7-May-20 13:21pm
Doe the properties "codes_format1" etc already exist on the class?
RmcbainTheThird 7-May-20 13:30pm
that snippet will not even compile. You are returning values before declaring it,you mark your get as a string and yet when you do declare it you declare it as an array.

1 solution

So you have a column in the DB called codes which is actually comma-delineated values

You have a generic get...set for this public property.
The code you have presented references a property/field called _codes

Normally an underscore represents a private field and is intuitively named by the property which refers to it, something like this
private string _codes { get; set; }
public  string  codes { get { return _codes; } set { _codes = value; } }
Now what it looks like is that you want those codes to come back as a series of values. And you want those values trimmed of any white-space.

You can try working off of this block of code to bring that value back as an array
public string[] codes_format
          return (Array.ConvertAll(_codes.Split(','), p => p.Trim()));
.net333 8-May-20 7:35am
Thanks Myche... Really you saved my time...
MadMyche 8-May-20 8:42am
You are welcome

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