StringBuilder的? [英] StringBuilder?

查看:57
本文介绍了StringBuilder的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将值插入如下条件:


((E <= 100且E> 79)和(F <= 59且F> 39 ))或((E <= 79且E> 59)

和(F <= 39且F> 19))或((E <= 59且E> 39)和(F <= 19且F>

-1))


其中E和F具有数值,并测试条件是否为真。

这些条件中有400个和10个变量A。 - J。


我认为我可以使用VB.Net中的

字符串构建器构建表达式。我试过但我不知道怎么做。任何

的想法。这是我一直在玩的一些代码。


Dim A,B,C,D,E,F,G,H,I,J字符串

A = CStr(dt.Rows.Item(0).Item(0))

B = CStr(dt.Rows.Item(0).Item(1))

C = CStr(dt.Rows.Item(0).Item(2))

D = CStr(dt.Rows.Item(0).Item(3))

E = CStr(dt.Rows.Item(0).Item(4))

F = CStr(dt.Rows.Item(0).Item(5 ))

G = CStr(dt.Rows.Item(0).Item(6))

H = CStr(dt.Rows.Item(0).Item (7))

I = CStr(dt.Rows.Item(0).Item(8))

J = CStr(dt.Rows.Item(0) .Item(9))


Dim xx As Boolean

Dim dc As DataColumn = ds.Tables(0).Columns.Add()

ds.Tables(0).Columns.Add(" calcTrait")

对于x = 0到ds.Tables(0).Rows.Count - 1

Dim sb As New System.Text.StringBuilder

Dim condition As String =

CStr(ds.Tables(0).Rows(x).Item( 0))

sb.Append(条件)

sb.Replace(" And"," xxx")

s b.Replace(A,A)

sb.Replace(" B",B)

sb.Replace(" C",C)

sb.Replace(" D",D)

sb.Replace(" E",E)

sb.Replace(" ; F",F)

sb.Replace(" G",G)

sb.Replace(" H",H)

sb.Replace(" I",I)

sb.Replace(" J",J)

sb.Replace(" xxx"," ;和")

xx = CBool​​(sb.ToString)

如果CBool​​(xx)那么

ds.Tables.Item(0) .Rows(x).Item(" calctrait")=

sb.ToString

结束如果

下一个x

x =没什么

解决方案

J,


这不是字符串生成器问题..使用RegEx或简单的字符串


-

Kathleen Dollard

Microsoft MVP

作者" ; Microsoft .NET中的代码生成"


嗯...你能给一个实际目标是什么的稍微宽泛的图片?

似乎可能有更好的选择,但很难从列表中看出
。您是否试图从数据库中隔离出符合数百条标准的数据库?


另外作为旁注......考虑稍微表达条件

不同,例如(E> 79和E< = 100)它往往使它稍微更多

显然E应该在该范围之间。


汤姆


J琼斯 < ji*@nospam.com>写道..

我需要将值插入如下条件:

((E< = 100和E> 79)和(F< = 59 And F> 39))或((E <= 79且E> 59)
和(F <= 39且F> 19))或((E <= 59且E> 1)。 39)和(F <= 19且F>
-1))

其中E和F具有数值,并测试条件是否为真。
这些条件中有400个和10个变量A。 - J。

我认为我可以使用VB.Net中的
stringbuilder构建表达式。我试过但我不知道怎么做。任何想法。这是我一直在玩的一些代码。



它看起来真正需要的是Eval语句,它不是
.NET支持
(据我所知)。我确实看到了一个非常有趣的

解决方法,使用编译成DLL的JavaScript并在

VB.NET中声明使用eval。


如果你在google上进行搜索,你可能会找到一种方法来实现这一点,它会来几次没有很好的解决方案。然而,正如汤姆·莱兰所指出的那样,你可能想要概述一下你实际上想要实现的目标,我们可以猜测,但这样做要容易得多。明确告诉。


最诚挚的问候 - OHM


O_H_M {at} BTInternet {dot} com



J Jones写道:

我需要将值插入如下条件:

((E< = 100和E> 79)和(F <= 59且F> 39))或((E <= 79且E>
59)和(F <= 39且F> 19))或((E< ; = 59和E> 39)和(F <= 19
和F> -1))

其中E和F有数值,并测试条件是否为真。这些条件中有400个和10个变量A。 - J。

我认为我可以使用VB.Net中的
stringbuilder构建表达式。我试过但我不明白我怎么做。
任何想法。这是我一直在玩的一些代码。

Dim A,B,C,D,E,F,G,H,I,J字符串
A = CStr( dt.Rows.Item(0).Item(0))
B = CStr(dt.Rows.Item(0).Item(1))
C = CStr(dt.Rows.Item( 0).Item(2))
D = CStr(dt.Rows.Item(0).Item(3))
E = CStr(dt.Rows.Item(0).Item(4 ))
F = CStr(dt.Rows.Item(0).Item(5))
G = CStr(dt.Rows.Item(0).Item(6))
H = CStr(dt.Rows.Item(0).Item(7))
I = CStr(dt.Rows.Item(0).Item(8))
J = CStr(dt。 Rows.Item(0).Item(9))

Dim xx As Boolean
Dim dc As DataColumn = ds.Tables(0).Columns.Add()
ds .Tables(0).Columns.Add(" calcTrait")
对于x = 0到ds.Tables(0).Rows.Count - 1
Dim sb As New System.Text.StringBuilder
Dim condition As String =
CStr(ds.Tables(0).Rows(x).Item(0))
sb.Append(condition)
sb.Replace("" ,xxx)
sb.Replace(A,A)
sb.Replace(" B",B)
sb.Replace(" C",C) )
sb.Replace(" D",D)
sb.Replace(E,E)
sb.Replace(F,F)
sb.Replace(" G",G)
sb.Replace(" H",H)
sb.Replace(I,I)
sb.Replace(" ; J",J)
sb.Replace(" xxx","和")
xx = CBool​​(sb.ToString)
如果CBool​​(xx)那么
ds.Tables.Item(0).Rows(x).Item(" calctrait")=
s b.ToString
结束如果
下一个x
x =没什么




-


I need to plug values into a condition like:

((E <= 100 And E > 79) And (F <= 59 And F > 39)) Or ((E <= 79 And E > 59)
And (F <= 39 And F > 19)) Or ((E <= 59 And E > 39) And (F <= 19 And F >
-1))

Where "E" and "F" have numeric values, and test if the condition is true.
There are 400 of these conditions and 10 variables "A" - "J".

What I thought was that I could build up an expression using the
stringbuilder in VB.Net. I have tried but I dont see how I can do it. Any
ideas. Here is some code i''ve been playing with.

Dim A, B, C, D, E, F, G, H, I, J As String
A = CStr(dt.Rows.Item(0).Item(0))
B = CStr(dt.Rows.Item(0).Item(1))
C = CStr(dt.Rows.Item(0).Item(2))
D = CStr(dt.Rows.Item(0).Item(3))
E = CStr(dt.Rows.Item(0).Item(4))
F = CStr(dt.Rows.Item(0).Item(5))
G = CStr(dt.Rows.Item(0).Item(6))
H = CStr(dt.Rows.Item(0).Item(7))
I = CStr(dt.Rows.Item(0).Item(8))
J = CStr(dt.Rows.Item(0).Item(9))

Dim xx As Boolean
Dim dc As DataColumn = ds.Tables(0).Columns.Add()
ds.Tables(0).Columns.Add("calcTrait")
For x = 0 To ds.Tables(0).Rows.Count - 1
Dim sb As New System.Text.StringBuilder
Dim condition As String =
CStr(ds.Tables(0).Rows(x).Item(0))
sb.Append(condition)
sb.Replace("And", "xxx")
sb.Replace("A", A)
sb.Replace("B", B)
sb.Replace("C", C)
sb.Replace("D", D)
sb.Replace("E", E)
sb.Replace("F", F)
sb.Replace("G", G)
sb.Replace("H", H)
sb.Replace("I", I)
sb.Replace("J", J)
sb.Replace("xxx", "And")
xx = CBool(sb.ToString)
If CBool(xx) Then
ds.Tables.Item(0).Rows(x).Item("calctrait") =
sb.ToString
End If
Next x
x = Nothing

解决方案

J,

It isn''t a string builder problem.. Use RegEx or a simple string

--
Kathleen Dollard
Microsoft MVP
Author "Code Generation in Microsoft .NET"


Ummm... can you give a slightly broader picture of what the actual goal is?
It seems possible that there may be a better alternative but it''s hard to
tell from the listing. Are you trying to isolate rows from a database that
match hundreds of criteria?

Also as a sidenote... consider expressing the conditions slightly
differently e.g. (E > 79 And E <= 100) It tends to make it slightly more
obvious that E is supposed to be between that range.

Tom

"J Jones" <ji*@nospam.com> wrote..

I need to plug values into a condition like:

((E <= 100 And E > 79) And (F <= 59 And F > 39)) Or ((E <= 79 And E > 59)
And (F <= 39 And F > 19)) Or ((E <= 59 And E > 39) And (F <= 19 And F >
-1))

Where "E" and "F" have numeric values, and test if the condition is true.
There are 400 of these conditions and 10 variables "A" - "J".

What I thought was that I could build up an expression using the
stringbuilder in VB.Net. I have tried but I dont see how I can do it. Any
ideas. Here is some code i''ve been playing with.



What you really need by the looks of it is the Eval statement which is no
longer supported by .NET ( To my knowledge ). I did see a very interesting
workaround to this using a JavaScript compiled into a DLL and declared in
VB.NET to use the eval.

If you do a search on google, you might find a way of doing this, its come
up a few times without a great solution. However, as tom leylan pointed out,
you may want to outline what it is you are actually trying to achieve we can
guess but it''s a lot easier to be told explicitly.

Best Regards - OHM

O_H_M{at}BTInternet{dot}com


J Jones wrote:

I need to plug values into a condition like:

((E <= 100 And E > 79) And (F <= 59 And F > 39)) Or ((E <= 79 And E >
59) And (F <= 39 And F > 19)) Or ((E <= 59 And E > 39) And (F <= 19
And F > -1))

Where "E" and "F" have numeric values, and test if the condition is
true. There are 400 of these conditions and 10 variables "A" - "J".

What I thought was that I could build up an expression using the
stringbuilder in VB.Net. I have tried but I dont see how I can do it.
Any ideas. Here is some code i''ve been playing with.

Dim A, B, C, D, E, F, G, H, I, J As String
A = CStr(dt.Rows.Item(0).Item(0))
B = CStr(dt.Rows.Item(0).Item(1))
C = CStr(dt.Rows.Item(0).Item(2))
D = CStr(dt.Rows.Item(0).Item(3))
E = CStr(dt.Rows.Item(0).Item(4))
F = CStr(dt.Rows.Item(0).Item(5))
G = CStr(dt.Rows.Item(0).Item(6))
H = CStr(dt.Rows.Item(0).Item(7))
I = CStr(dt.Rows.Item(0).Item(8))
J = CStr(dt.Rows.Item(0).Item(9))

Dim xx As Boolean
Dim dc As DataColumn = ds.Tables(0).Columns.Add()
ds.Tables(0).Columns.Add("calcTrait")
For x = 0 To ds.Tables(0).Rows.Count - 1
Dim sb As New System.Text.StringBuilder
Dim condition As String =
CStr(ds.Tables(0).Rows(x).Item(0))
sb.Append(condition)
sb.Replace("And", "xxx")
sb.Replace("A", A)
sb.Replace("B", B)
sb.Replace("C", C)
sb.Replace("D", D)
sb.Replace("E", E)
sb.Replace("F", F)
sb.Replace("G", G)
sb.Replace("H", H)
sb.Replace("I", I)
sb.Replace("J", J)
sb.Replace("xxx", "And")
xx = CBool(sb.ToString)
If CBool(xx) Then
ds.Tables.Item(0).Rows(x).Item("calctrait") =
sb.ToString
End If
Next x
x = Nothing



--


这篇关于StringBuilder的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆