Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

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?
Avatar of VBdotnet2005
VBdotnet2005
Flag of United States of America image

ASKER

This is what I am after.

XPCollection1.Filter = New InOperator("Name", New String() {"John", "Mike", "Nick"})
Avatar of Fernando Soto
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

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 })
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" }
"So where are these keept before getting to this point?"
I am planing to return it from sql query. This is not a problem.
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?
"Is all the names in a single string returned from SQL?"
correct
I am sorry.

from sql
column Name

John
Mike
Nick

I want to return like "john", "mike", "Nick" as a single string.
Let try it this way please post the actual SQL query and the code you are actually using to call the database.
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" ?
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did that work out for you?
yes, Thank you Fernando.
Not a problem VBdotnet2005, glad to help.