Allan
asked on
String Value Into List
Hi Experts!
Thanks for reading this.
If you have a string that contains a list of ids with
comma as a delimiter:
"332, 123, 782, 2, 87, 30, 1, 45, 32"
How do you get it into the var "tids":
Thanks for reading this.
If you have a string that contains a list of ids with
comma as a delimiter:
"332, 123, 782, 2, 87, 30, 1, 45, 32"
How do you get it into the var "tids":
var tids = new List<string>();
TIA!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So tried this:
string str = "332, 123, 782, 2, 87, 30, 1, 45, 32";
var tids = str.Split(",");
Got these errors:
Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
Error 2 Argument 1: cannot convert from 'string' to 'char[]'
Tried:
var tids = str.Split(Char(44));
but don't know what references Char is from ..
Any ideas?
string str = "332, 123, 782, 2, 87, 30, 1, 45, 32";
var tids = str.Split(",");
Got these errors:
Error 1 The best overloaded method match for 'string.Split(params char[])' has some invalid arguments
Error 2 Argument 1: cannot convert from 'string' to 'char[]'
Tried:
var tids = str.Split(Char(44));
but don't know what references Char is from ..
Any ideas?
ASKER
Basically want to go from
//containing a list of IDs from a string w/ delimiter
var tids = new List<string>();
to:
var tntable = tids.AsQueryble();
//containing a list of IDs from a string w/ delimiter
var tids = new List<string>();
to:
var tntable = tids.AsQueryble();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect kaufmed. Thanks again.
I will split points.
I will split points.
Just a small note...
Your original request was for a LIST, but Split() returns an ARRAY.
If you want a List, then pass the results of Split() to the Constructor:
Your original request was for a LIST, but Split() returns an ARRAY.
If you want a List, then pass the results of Split() to the Constructor:
string data = "332, 123, 782, 2, 87, 30, 1, 45, 32";
var tids = new List<string>(data.Replace(", ", ",").Split(','));
Note that I threw in a Replace() call to get rid of the space after the comma, which would have been present in the split strings.
ASKER
Thank you Idle_Mind; I have sooooo much to learn.
ASKER
So, that's the same as a List<string>?
I will try it now ...