String.Replace不工作??? [英] String.Replace not working???

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

问题描述

这太奇怪了,我犹豫发布它,但我需要让它工作。


我的代码看起来像这样......


Private Const cmdTestResourcesSel =" SELECT * FROM TResources" &安培; _

"在哪里场景=

@场景"

Dim cmdstr as String


cmdstr = cmdTestResourcesSel

如果历史然后

cmdstr.Replace(" TResources"," TResourcesHistory")

结束如果

Dim cmdS As SqlCommand = New SqlCommand( cmdstr,cnTest)


历史是真的。走出如果语句,cmdstr不变。

SQLCommand的CommandText包含TResources和TResources。不是TResourcesHistory

这个相同的代码模板在大约十二个其他

位置的同一个程序中工作。没有例外。我可以在调试应用程序时在

命令窗口中对cmdstr进行替换,它运行正常。


这有什么用?


感谢您的帮助。


BBM

This is so bizarre I hesitate to post it, but I need to get this working.

My code looks like this...

Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _
" WHERE Scenario =
@Scenario"
Dim cmdstr as String

cmdstr = cmdTestResourcesSel
If history Then
cmdstr.Replace("TResources", "TResourcesHistory")
End If
Dim cmdS As SqlCommand = New SqlCommand(cmdstr, cnTest)

History is true. Coming out of the "if" statement, cmdstr is unchanged.
CommandText of the SQLCommand contains "TResources" not "TResourcesHistory"
This same code template works in the same program in about a dozen other
places. No exceptions thrown. I can do the replace on cmdstr in the
command window while debugging the app and it works fine.

What''s up with this???

Thanks for your help.

BBM

推荐答案

大家好,


我通过将cmdstr更改为StringBuilder对象来实现这一点,但我不知道
知道为什么我必须这样做。如果有人能在这里发光,我会很感激

吧。


BBM


" BBM" ;写道:
Hi everyone,

I got this to work by changing cmdstr to a StringBuilder object, but I don''t
know why I had to do this. If anyone can shed some light here I''d appreciate
it.

BBM

"BBM" wrote:
这是如此奇怪,我犹豫发布它,但我需要让它工作。

我的代码看起来像这样...

私有Const cmdTestResourcesSel =" SELECT * FROM TResources" &安培; _
情节=
@ Scenario"
Dim cmdstr as String

cmdstr = cmdTestResourcesSel
如果历史那么
cmdstr.Replace(" TResources"," ; TResourcesHistory")
结束如果
Dim cmdS As SqlCommand = New SqlCommand(cmdstr,cnTest)

历史是真的。走出如果声明,cmdstr不变。
SQLCommand的CommandText包含TResources。不是TResourcesHistory
这个相同的代码模板在大约十几个其他地方的同一个程序中工作。没有例外。我可以在调试应用程序时在
命令窗口中对cmdstr进行替换,它运行正常。

这是怎么回事?

感谢您的帮助。

BBM
This is so bizarre I hesitate to post it, but I need to get this working.

My code looks like this...

Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _
" WHERE Scenario =
@Scenario"
Dim cmdstr as String

cmdstr = cmdTestResourcesSel
If history Then
cmdstr.Replace("TResources", "TResourcesHistory")
End If
Dim cmdS As SqlCommand = New SqlCommand(cmdstr, cnTest)

History is true. Coming out of the "if" statement, cmdstr is unchanged.
CommandText of the SQLCommand contains "TResources" not "TResourcesHistory"
This same code template works in the same program in about a dozen other
places. No exceptions thrown. I can do the replace on cmdstr in the
command window while debugging the app and it works fine.

What''s up with this???

Thanks for your help.

BBM



替换不会修改原始字符串。它返回一个新的

替换。


意思是,你必须将Replace的返回值赋给变量。这是

记录完好。


" BBM" < bb*@bbmcompany.com>在消息中写道

news:35 ********************************** @ microsof t.com ...
Replace does not modify the original string. It returns a new one with the
replacements.

Meaning, you have to assign the return of Replace to a variable. This is
well documented.

"BBM" <bb*@bbmcompany.com> wrote in message
news:35**********************************@microsof t.com...
这是如此奇怪,我犹豫发布它,但我需要让它工作。

我的代码看起来像这样...

私有Const cmdTestResourcesSel =" SELECT * FROM TResources" &安培; _
情节=
@ Scenario"
Dim cmdstr as String

cmdstr = cmdTestResourcesSel
如果历史那么
cmdstr.Replace(" TResources"," ; TResourcesHistory")
结束如果
Dim cmdS As SqlCommand = New SqlCommand(cmdstr,cnTest)

历史是真的。走出如果声明,cmdstr不变。
SQLCommand的CommandText包含TResources。不是
TResourcesHistory
这个相同的代码模板在大约十几个其他地方的同一个程序中工作。没有例外。我可以在调试应用程序时在
命令窗口中对cmdstr进行替换,它运行正常。

这是怎么回事?

谢谢你的帮助。

BBM
This is so bizarre I hesitate to post it, but I need to get this working.

My code looks like this...

Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _
" WHERE Scenario =
@Scenario"
Dim cmdstr as String

cmdstr = cmdTestResourcesSel
If history Then
cmdstr.Replace("TResources", "TResourcesHistory")
End If
Dim cmdS As SqlCommand = New SqlCommand(cmdstr, cnTest)

History is true. Coming out of the "if" statement, cmdstr is unchanged.
CommandText of the SQLCommand contains "TResources" not
"TResourcesHistory"
This same code template works in the same program in about a dozen other
places. No exceptions thrown. I can do the replace on cmdstr in the
command window while debugging the app and it works fine.

What''s up with this???

Thanks for your help.

BBM



BBM,


dim myresultstring as string = cmdstr.Replace(" TResources",

" TResourcesHistory")

甚至

cmdstr = cmdstr.Replace(" TResources"," TResourcesHistory")

我希望这会有所帮助


Cor
BBM,

dim myresultstring as string = cmdstr.Replace("TResources",
"TResourcesHistory")
or even
cmdstr = cmdstr.Replace("TResources", "TResourcesHistory")

I hope this helps

Cor


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

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