0

I store values that i save through a form in a database column named 'Properties' like:

value1#||#value2#||#value3#||#value4

The question is how to retrieve for example 'value2' from this string when using 'For Each row As DataRow In table.Rows'.

Using 'row("Properties") obviously returns: value1#||#value2#||#value3#||#value4.

How to construct something with a split function to retrieve the specific value (ex. value2)?

Thanks in advance!

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Marcellino Bommezijn
  • 2,889
  • 1
  • 16
  • 14

1 Answers1

1

Just use split("#||#") to split the string by values. In your case to get value2 you would do:

String[] splitValues = row("Properties").ToString().Split(new String[] {"#||#"}, StringSplitOptions.None);
String value2 = splitValues[1];
nmat
  • 7,430
  • 6
  • 30
  • 43
  • A couple of minor edits required. Split should be with a capital S. Also if passing a string array to Split the StringSplitOptions parameter is required. http://msdn.microsoft.com/en-gb/library/tabh47cf.aspx – Andy Nichols Apr 16 '13 at 08:56
  • Thanks! It returns this error: BC30311: Value of type '1-dimensional array of String' cannot be converted to 'Char' for the first line of code. – Marcellino Bommezijn Apr 16 '13 at 09:05
  • @MarcellinoBommezijn fixed. I'm writing it from the top of my head, let's hope that it is ok now :) – nmat Apr 16 '13 at 09:07
  • @nmat The adjusted code returns: BC30311: Value of type '1-dimensional array of String' cannot be converted to 'String'. – Marcellino Bommezijn Apr 16 '13 at 09:09
  • @Marcellino Bommezijn Did you add the brackets to the variable declaration? `String[] splitValues`. If so, the problem must be with row("Properties"). Confirm that row("Properties") returns the value of a single cell from your table – nmat Apr 16 '13 at 09:16
  • @nmat Yes, that seems the trouble. I need to review my data access to include this column. Thanks for your swift solution! Appreciate it! – Marcellino Bommezijn Apr 16 '13 at 09:21
  • @nmat To confirm: the solution works like a charm. The problem was a stored procedure that didn't had the column in it's SELECT statement. – Marcellino Bommezijn Apr 16 '13 at 09:28