使用双引号作为字符串 [英] use of double quotes as string
本文介绍了使用双引号作为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 vb.net 中开发
I am developing in vb.net
Dim dtDetails As DataTable = Utility.GetDetailsTable()
Dim resource_id As String = ""
Dim dtrow = dtDetails.Select("id='" & user_id & "'")
If dtrow.Length > 0 Then
For i As Integer = 0 To dtrow.Length - 1
If i > 0 Then
resource_id += ","
End If
resource_id += Convert.ToString(dtrow(i)("instance_id"))
Next
但是当我进一步使用 resource_id 时,它不起作用,Docs 返回为空
but when I use resource_id further, it is not working, Docs returns as empty
Dim resource_ids = New BsonValue() {resource_id}
Dim querys = Query.And(
Query.EQ("user_id", user_id),
Query.In("resource_id", resource_ids)
)
Dim Docs = ceilometer.GetCollection("meter").Find(querys)
因为我需要这种格式的BsonValue(){"resource_id1","resource_id2"}
.请帮我解决这个问题
because I need it in this format BsonValue(){"resource_id1","resource_id2"}
. Please help me to solve this
推荐答案
从我对你的问题的理解来看,我相信你需要将动态 id 添加到 BsonValue
数组中.使用此答案的扩展:
From how I understood your question, I believe you need to add the dynamic ids to the BsonValue
array. Using an extension from this answer:
<Extension()> _
Public Sub Add(Of T)(ByRef arr As T(), item As T)
Array.Resize(arr, arr.Length + 1)
arr(arr.Length - 1) = item
End Sub
然后您可以在代码中将其用作:
Which you can then use in your code as:
Dim dtDetails As DataTable = Utility.GetDetailsTable()
Dim resource_ids As new BsonArray
Dim dtrow = dtDetails.Select("id='" & user_id & "'")
If dtrow.Length > 0 Then
For i As Integer = 0 To dtrow.Length - 1
resource_ids.Add(Convert.ToString(dtrow(i)("instance_id")))
Next
End If
Dim queries = Query.And(
Query.EQ("user_id", user_id),
Query.In("resource_id", resource_ids)
)
Dim Docs = ceilometer.GetCollection("meter").Find(queries)
这篇关于使用双引号作为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文