Avatar of Allan
Allan
Flag for United States of America 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":

var tids = new List<string>();

Open in new window

TIA!
.NET ProgrammingC#SQL

Avatar of undefined
Last Comment
Allan

8/22/2022 - Mon
SOLUTION
Kyle Abrahams

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Allan

ASKER
wow; that was super quick ged325.

So, that's the same as a List<string>?
I will try it now ...
Allan

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?
Allan

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();
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
kaufmed

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Allan

ASKER
perfect kaufmed. Thanks again.

I will split points.
Mike Tomlinson

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:
            string data = "332, 123, 782, 2, 87, 30, 1, 45, 32";
            var tids = new List<string>(data.Replace(", ", ",").Split(','));

Open in new window

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.
Allan

ASKER
Thank you Idle_Mind; I have sooooo much to learn.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.