2

I have a datacolumn, which I would like to split e.g.

ALICE MEGAN JANET

split to: ALICE, MEGAN, JANET

I know I can do it with for loops but I'd like to know if there's any built-in functions in .Net Framework. Thanks.

EDIT: My question is not clear. Let me try to re-articulate:

I have a datacolumn i.e. one column of many rows of names in this context:

datarow[0]["name"] = ALICE
datarow[1]["name"] = MEGAN
datarow[2]["name"] = JANET

I'd like to know what's the most elegant way to split this column of names into a string of format: ALICE, MEGAN, JANET

What do I need it for: I will use this format in a where clause query.

I'm using .Net C# 2.0

hyperkittie
  • 641
  • 6
  • 16

4 Answers4

3
string[] parts = "ALICE MEGAN JANET".Split();
Petar Ivanov
  • 91,536
  • 11
  • 82
  • 95
  • 1
    The solution that you've provided does not split the values in a datacolumn. Datacolumn - by definition is one column of many rows of names in this context: row[0]["name"] = ALICE, row[1]["name"] = MEGAN, row[1]["name"] = JANET. – hyperkittie Jul 18 '11 at 09:35
1

Use the text.Split(new char[] {' '}) code to do this. This method is described at:

string.Split

platon
  • 5,310
  • 1
  • 22
  • 24
0
Try This

string[] parts = "ALICE MEGAN JANET".Split(' ');

SMK
  • 2,098
  • 2
  • 13
  • 21
0

try this:

string[] results = dt.Rows[row_number]["col_name"].ToString().Split(' ');

"dt" is the DataTable object

Ovais Khatri
  • 3,201
  • 16
  • 14