一个相当于sql IN函数的vb.net? [英] a vb.net equivalent to the sql IN function?
问题描述
我需要从配置文件中获取一组以逗号分隔的客户端ID,以便在运行主处理循环时测试
。
如果给定的clientid匹配列表中的任何ID,我都不想向他们发送
电子邮件。
编码的最佳方法是什么?我想的是如果
currentClientID不在这些clientids的列表中,那么.....
谢谢,
Greg
I need to get a set of comma delimited client ids from a config file to test
against while running through my main processing loop.
If a given clientid matches any of the ids in the list, I don''t want to send
email to them.
What is the best way to code that? I was thinking of the idea of if
currentClientID is not in the list of these clientids, then .....
Thanks,
Greg
推荐答案
你好hazz,
虽然不是很性感,一个简单的方法这样做会是:
Dim tIDStr As String =" 1,2,3,4,5,6,7,8,9"
Dim tIDs()As String = tIDStr.Split(",")
If(tIDs.GetLowerBound(0) - 1)= Array.IndexOf(tIDs," 3" ;)然后
''不在阵列中
否则
''在阵列中
结束如果
当然还有其他方法。
享受,
-Boo
Hello hazz,
While not incredibly sexy, an easy way to do this would be:
Dim tIDStr As String = "1,2,3,4,5,6,7,8,9"
Dim tIDs() As String = tIDStr.Split(",")
If (tIDs.GetLowerBound(0) - 1) = Array.IndexOf(tIDs, "3") Then
'' NOT IN ARRAY
Else
'' IN ARRAY
End If
There are of course other methods.
Enjoy,
-Boo
我需要从配置文件中获取一组以逗号分隔的客户端ID,以便在运行我的主处理循环时测试
。
如果给定的clientid匹配任何ID列表,我不想发送
em对他们有所帮助。
编码的最佳方法是什么?我想到了如果
currentClientID不在这些clientid列表中的想法,那么.....
谢谢,
Greg
I need to get a set of comma delimited client ids from a config file
to test
against while running through my main processing loop.
If a given clientid matches any of the ids in the list, I don''t want
to send
email to them.
What is the best way to code that? I was thinking of the idea of if
currentClientID is not in the list of these clientids, then .....
Thanks,
Greg
>
GhostInAK写道:
GhostInAK wrote:
你好hazz,
虽然不是很性感,但很容易要做到这一点将是:
Dim tIDStr As String =" 1,2,3,4,5,6,7,8,9"
Dim tIDs()As String = tIDStr.Split(",")
如果(tIDs.GetLowerBound(0) - 1)= Array.IndexOf(tIDs," 3")那么
''NOT IN ARRAY
其他
''在阵列中
结束如果
当然还有其他方法。
Hello hazz,
While not incredibly sexy, an easy way to do this would be:
Dim tIDStr As String = "1,2,3,4,5,6,7,8,9"
Dim tIDs() As String = tIDStr.Split(",")
If (tIDs.GetLowerBound(0) - 1) = Array.IndexOf(tIDs, "3") Then
'' NOT IN ARRAY
Else
'' IN ARRAY
End If
There are of course other methods.
你可以把它归结为一条(丑陋)线:
Dim theList As String =" 1,2,33,56,7,8,9"
Dim theItem As String =" 56"
Dim包含As Boolean
包含= DirectCast(theList.Split(") ;,c),
IList) .Contains(theItem)
但是这应该真的隐藏在一个实用程序类中,只有
公开一个包含逗号分隔字符串的Contains方法一个
项目。
-
Larry Lard
回复团体请
You can get this down to one (ugly) line:
Dim theList As String = "1,2,33,56,7,8,9"
Dim theItem As String = "56"
Dim contains As Boolean
contains = DirectCast(theList.Split(","c),
IList).Contains(theItem)
But this should really be hidden away in a utility class that just
exposes a Contains method that takes a comma-delimited string and an
item.
--
Larry Lard
Replies to group please
Larry Lard写道:
Larry Lard wrote:
GhostInAK写道:
GhostInAK wrote:
Dim tIDStr As String =" 1,2,3,4,5,6,7,8,9"
Dim tIDs()As String = tIDStr.Split("," )
如果(tIDs.GetLowerBound(0) - 1)= Array.IndexOf(tIDs," 3")那么
当然还有其他方法。
Dim tIDStr As String = "1,2,3,4,5,6,7,8,9"
Dim tIDs() As String = tIDStr.Split(",")
If (tIDs.GetLowerBound(0) - 1) = Array.IndexOf(tIDs, "3") Then
There are of course other methods.
好吧,我[可能]会在这里重新点燃一场宗教战争,但是,
希望同时学到一些东西...... 。
在VB6中,我已经完成了[类似]这样的事情:
Dim sSearch As String =" ; 1,2,3,4,5,6,7,8,9"
Dim sTarget As String =" 4"
If( "," &安培; sSearch& ",")。IndexOf(","& sTarget&",")> -1然后
。 。 。
结束如果
在我们的勇敢新世界中这是可怕的,可怕的错误吗?
TIA,
Phill W.
OK, I''m [probably] going to rekindle a Religious War here but,
hopefully, learn something at the same time ...
In VB6, I''d have done [something like] this:
Dim sSearch As String = "1,2,3,4,5,6,7,8,9"
Dim sTarget As String = "4"
If ("," & sSearch & ",").IndexOf("," & sTarget & ",") > -1 Then
. . .
End If
Is this horribly, horribly wrong in our Brave New World?
TIA,
Phill W.
这篇关于一个相当于sql IN函数的vb.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!