|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
IN Function ?What is the quivelant to the SQL IN function in VB.NET? Eg. I need to know
if a string contains a specific character. dim varwhatever as string if varwhatever in ("5","6","9") then ... I've been using: if varwhatever="5" or varwhatever="6" or varwhatever="9" then ... But there must be a better, more effecient way. Thanks a lot. Instr() will return the position of a character in a string.
i.e. dim str as string = "569" dim i as integer = str.instr("6") ' i = 2 Thanks, Seth Rowe Jay wrote: Show quoteHide quote > What is the quivelant to the SQL IN function in VB.NET? Eg. I need to know > if a string contains a specific character. > > dim varwhatever as string > if varwhatever in ("5","6","9") then ... > > I've been using: > > if varwhatever="5" or varwhatever="6" or varwhatever="9" then ... > > But there must be a better, more effecient way. > > Thanks a lot. Jay wrote:
> What is the quivelant to the SQL IN function in VB.NET? Eg. I need to know If INSTR("5,6,9,", varwhatever & ',') > 0 Then ...> if a string contains a specific character. > > dim varwhatever as string > if varwhatever in ("5","6","9") then ... > > I've been using: > > if varwhatever="5" or varwhatever="6" or varwhatever="9" then ... > > But there must be a better, more effecient way. > > Thanks a lot. B. My personal preference is to use select case.
If you use the InStr trick be aware to add delimiters both before and after both strings. For example the code below will find "9," in "5,6,19,20" -- Patrice "Brian Tkatch" <Maxwell_Sm***@ThePentagon.com> a écrit dans le message de news: 1164120563.461024.108***@k70g2000cwa.googlegroups.com...Show quoteHide quote > Jay wrote: >> What is the quivelant to the SQL IN function in VB.NET? Eg. I need to >> know >> if a string contains a specific character. >> >> dim varwhatever as string >> if varwhatever in ("5","6","9") then ... >> >> I've been using: >> >> if varwhatever="5" or varwhatever="6" or varwhatever="9" then ... >> >> But there must be a better, more effecient way. >> >> Thanks a lot. > > If INSTR("5,6,9,", varwhatever & ',') > 0 Then ... > > B. > Patrice wrote:
Show quoteHide quote > My personal preference is to use select case. True. In my defence, i only say him use one digit. :)> > If you use the InStr trick be aware to add delimiters both before and after > both strings. For example the code below will find "9," in "5,6,19,20" > -- > Patrice > > "Brian Tkatch" <Maxwell_Sm***@ThePentagon.com> a écrit dans le message de > news: 1164120563.461024.108***@k70g2000cwa.googlegroups.com... > > Jay wrote: > >> What is the quivelant to the SQL IN function in VB.NET? Eg. I need to > >> know > >> if a string contains a specific character. > >> > >> dim varwhatever as string > >> if varwhatever in ("5","6","9") then ... > >> > >> I've been using: > >> > >> if varwhatever="5" or varwhatever="6" or varwhatever="9" then ... > >> > >> But there must be a better, more effecient way. > >> > >> Thanks a lot. > > > > If INSTR("5,6,9,", varwhatever & ',') > 0 Then ... > > > > B. > > > If you use the InStr trick be aware to add delimiters both before and after > both strings. For example the code below will find "9," in "5,6,19,20" B. I would use a Generic List.
Dim checkSet As New Generic.List(Of String) checkSet.Add("apple") checkSet.Add("banana") checkSet.Add("grape") If (checkSet.Contains("apple") = True) Then ' ... add successful IN code here... End If The next version of Visual Basic ("Orcas" or 9.0) will contain a new feature called LINQ that provides SQL-like queries within the Visual Basic language. ----- Tim Patrick - www.timaki.com Start-to-Finish Visual Basic 2005 Show quoteHide quote > What is the quivelant to the SQL IN function in VB.NET? Eg. I need to > know if a string contains a specific character. > > dim varwhatever as string > if varwhatever in ("5","6","9") then ... > I've been using: > > if varwhatever="5" or varwhatever="6" or varwhatever="9" then ... > > But there must be a better, more effecient way. > > Thanks a lot. > Everyone has shown good ideas. I'd thought I'd throw another suggestion
out there. How about using a Generic function? Private Function IsIn(Of T)(ByVal Value As T, ByVal ParamArray Values() As T) As Boolean For Each Item As T In Values If Item.Equals(Value) Then Return True Next Return False End Function Kelly Jay wrote: Show quoteHide quote > What is the quivelant to the SQL IN function in VB.NET? Eg. I need to > know if a string contains a specific character. > > dim varwhatever as string > if varwhatever in ("5","6","9") then ... > > I've been using: > > if varwhatever="5" or varwhatever="6" or varwhatever="9" then ... > > But there must be a better, more effecient way. > > Thanks a lot. > Jay wrote:
> I've been using: \\\> if varwhatever="5" or varwhatever="6" or varwhatever="9" then ... > But there must be a better, more effecient way. Select Case varwhatever Case "5", "6", "9" ...do your thing here End Select /// -- (O)enone Jay wrote:
Show quoteHide quote > What is the quivelant to the SQL IN function in VB.NET? Eg. I need to > know if a string contains a specific character. > > dim varwhatever as string > if varwhatever in ("5","6","9") then ... > > I've been using: > > if varwhatever="5" or varwhatever="6" or varwhatever="9" then ... > > But there must be a better, more effecient way. > > Thanks a lot. > Jay wrote:
> What is the quivelant to the SQL IN function in VB.NET? Eg. I need to Oops - twitchy Send finger, there ...> know if a string contains a specific character. > > dim varwhatever as string > if varwhatever in ("5","6","9") then ... If you want to be Stone-Age about it If varwhatever like "*[569]*" Then still works perfectly well. These days, you'd probably want a Regular Expression, something like (air-code warning): Dim mc As MatchCollection _ = Regex.Matches( varwhatever, "([569])" ) ? mc.Groups(0).Text HTH, Phill W.
Visual Basic to be discontinued in 2008??
Saving the Color value into a string Recommendations - VB .Net courses/seminars 2 dimensional array question programmatically allow tcp/ip to msde Radio buttons - best practice ClickOnce program fails to run properly after update "Attempted to read or write protected memory" since 10 days... ADO.NET Rowfilter - between 2 dates How to remove the last line in a RichTextBox |
|||||||||||||||||||||||