form strings

sample " Dim theVar = New List(Of String) From { "one", "two", "three" }
I don't know strings in advance. However, I want to be able to pass like below sample.

Dim mystring as as string = "one", "two", "three"
Dim theVar = New List(Of String) From { mystring }

What is the right way to form mystring variable? Is this possible?
VBdotnet2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VBdotnet2005Author Commented:
This is what I am after.

XPCollection1.Filter = New InOperator("Name", New String() {"John", "Mike", "Nick"})
0
Fernando SotoRetiredCommented:
Hi  VBdotnet2005;

This is incorrect string format statement.

Dim mystring as as string = "one", "two", "three"

Did you mean this?

Dim mystring As String = "one, two, three"

If so then this will work.
Dim mystring As String = "one, two, three"
Dim theVar As List(Of String) = mystring.Split(New Char() { ","C, " "C }, StringSplitOptions.RemoveEmptyEntries).ToList()

Open in new window

0
VBdotnet2005Author Commented:
Hi Fernando,

Did you see my link above?


XPCollection1.Filter = New InOperator("Name", New String() {"John", "Mike", "Nick"})

I don't know my string in advance. I want to pass like

dim mystring as string = form my string like "John", "Mike", "Nick"
XPCollection1.Filter = New InOperator("Name", New String() {mystring })
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Fernando SotoRetiredCommented:
I saw it after I posted my post and was about to post you back when you updated.

So it looks like you need an Array of String's. So where are these keept before getting to this point?

 { "John", "Mike", "Nick" }
0
VBdotnet2005Author Commented:
"So where are these keept before getting to this point?"
I am planing to return it from sql query. This is not a problem.
0
Fernando SotoRetiredCommented:
In order for someone to tell you how to get it into an Array we need to know how they are currently stored in memory. You state that you plan to return then in a SQL query. Is all the names in a single string returned from SQL? Is it in some collection being returned? Is Name the only column being returned or are there multiple columns being returned?
0
VBdotnet2005Author Commented:
"Is all the names in a single string returned from SQL?"
correct
0
VBdotnet2005Author Commented:
I am sorry.

from sql
column Name

John
Mike
Nick

I want to return like "john", "mike", "Nick" as a single string.
0
Fernando SotoRetiredCommented:
Let try it this way please post the actual SQL query and the code you are actually using to call the database.
0
VBdotnet2005Author Commented:
I don't have a problem calling sql or returning result. I can return it like from sql using datareader.

Dim sr As SqlDataReader = sqlcomm.ExecuteReader
Dim name_str As New List(Of String)

while sr.read
      name_str.add(sr.item("name")

end while

Now name_str should contains
John
Mike
Nick

How can I form this as a single string "John", "Mike", "Nick" ?
0
Fernando SotoRetiredCommented:
This is NOT a correctly formatted string, "John", "Mike", "Nick". The function you are trying to call is looking for an Array of String. To get that from your code in the last post you can do this after filling the List name_str.

name_str.ToArray()

And then pass that to the function.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
Did that work out for you?
0
VBdotnet2005Author Commented:
yes, Thank you Fernando.
0
Fernando SotoRetiredCommented:
Not a problem VBdotnet2005, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.