错误:string.substring.trim ="" (布尔表达式问题) [英] Bug: string.substring.trim = "" (boolean expression issue)

查看:92
本文介绍了错误:string.substring.trim ="" (布尔表达式问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我曾尝试在if语句中使用过的函数而且我已经发现无论我对代码做了多少工作,我都会发现它是预期的

结果不正确。


代码:


如果不是(strIn.Substring(410,10).Trim = 然后

''处理的东西

否则

''处理的东西

结束如果


string.substring(410,10).trim与一个emptry字符串相同,例如

"",当它进来时。所以

使用(strIn.Substring(410,10).Trim ="")时,预期结果应为TRUE,并使用NOT关键字

否定真假(反之亦然)。我无法得到这个DAMN

函数给我正确的布尔表达式,这是一个LOGIC错误...


我试过用过字符串.substring.trim = space(?)我已经尝试了

string.substring.trim<> ""并且这些都不会在If ... Then上下文中产生正确的布尔值


I have a function that I''ve tried using in an if then statement and I''ve
found that no matter how much reworking I do with the code, the expected
result is incorrect.

the code:

If Not (strIn.Substring(410, 10).Trim = "") Then
''Something processed
Else
''Something processed
End If

The string.substring(410,10).trim is equivelent to an emptry string, e.g.
"", when it comes in. So the expected result is supposed to be TRUE when you
use (strIn.Substring(410, 10).Trim = ""), and I use the NOT keyword which
negates the true to a false (or vice versa). I can not get this DAMN
function to give me the proper boolean expression, is this a LOGIC bug...

I''ve tried using string.substring.trim = space(?) and I''ve tried
string.substring.trim <> "" and none of these will yield the correct boolean
value in an If...Then context

推荐答案

" Darren安德森" <沓************ @ discussions.microsoft.com> schrieb:
"Darren Anderson" <Da************@discussions.microsoft.com> schrieb:
我有一个我曾尝试在if语句中使用的函数,我发现无论我对代码做了多少重做,预期
结果不正确。

代码:

如果不是(strIn.Substring(410,10).Trim ="")则
''处理过的东西
其他
''处理过的东西
结束如果

string.substring(410,10).trim对于一个emptry字符串是相同的,例如
"",当它进来时。所以当你使用

时,预期结果应为TRUE(strIn.Substring(410,10).Trim ="" ;),我使用NOT关键字
否定true为false(反之亦然)。我无法获得这个DAMN
函数给我正确的布尔表达式,这是一个LOGIC错误...
I have a function that I''ve tried using in an if then statement and I''ve
found that no matter how much reworking I do with the code, the expected
result is incorrect.

the code:

If Not (strIn.Substring(410, 10).Trim = "") Then
''Something processed
Else
''Something processed
End If

The string.substring(410,10).trim is equivelent to an emptry string, e.g.
"", when it comes in. So the expected result is supposed to be TRUE when
you
use (strIn.Substring(410, 10).Trim = ""), and I use the NOT keyword which
negates the true to a false (or vice versa). I can not get this DAMN
function to give me the proper boolean expression, is this a LOGIC bug...




您的代码对我来说很好。如果

修剪后的字符串不为空(零长度字符串),则''如果...则''中的条件为真。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL :http://dotnet.mvps.org/dotnet/faqs/>



Your code works just fine for me. The condition in ''If...Then'' is true if
the trimmed string is not empty (zero-length string).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Darren,

First"' 选择不是破碎的! :-)

http:// www .pragmaticprogrammer.com / p ... rule_list.html

您是否有任何示例代码可以演示感知到的问题?

Darren,
First "''Select isn''t Broken!" :-)

http://www.pragmaticprogrammer.com/p...rule_list.html
Do you have any sample code that demonstrates the perceived problem?

string.substring(410,10).trim相当于一个空字符串,例如
"",
如果将string.substring(410,10).trim赋给变量,

变量是什么?变量的长度是多少?


strIn来自哪里?它中是否有ChrW(0)字符?


ChrW(0)会使字符串显示为"在调试器中,当它实际上不是
时,因为ChrW(0)是一个有效的字符串。


如果运行以下内容你看到了什么?


Dim strIn As String = New String("" c,450)


Dim x As String = strIn.Substring(410, 10).Trim()

Debug.WriteLine(x," x")

Debug.WriteLine(x.Length," x.length")


Debug.WriteLine(Not(x.Trim()="")," not(x.trim = space)")

Debug .WriteLine(x.Trim()<>""," x.trim<> space")

Debug.WriteLine(x.Trim()="" ;,x.trim = space)

Debug.WriteLine(Not(strIn.Substring(410,10).Trim()=""),"不是
(substring.trim = space)")

Debug.WriteLine(strIn.Substring(410,10).Trim()<>"" ;,

" substring.trim<> space")

Debug.WriteLine(strIn.Substring(410,10).Trim()=&quo t;",

" substring.trim = space")

如果您使用原始字符串而不是新字符串,您会看到什么? (QUOT; c,

450)" for strIn?


希望这有帮助

Jay

" Darren Anderson" <沓************ @ discussions.microsoft.com>写在

消息新闻:96 ********************************** @ microsof t.com ...我有一个功能,我已尝试在if语句中使用,而且我已经发现无论我对代码做了多少重做,预期
结果不正确。

代码:

如果不是(strIn.Substring(410,10).Trim ="")那么
''东西处理
其他
''处理的东西
结束如果

string.substring(410,10).trim等同于一个emptry字符串,例如
,当它进来时。所以当你使用(strIn.Substring(410,10).Trim ="")时,预期结果应为TRUE,并且我使用NOT关键字
否定true为false(反之亦然)。我不能让这个DAMN
函数给我正确的布尔表达式,这是一个LOGIC错误...

我试过使用string.substring.trim = space(? )我已经尝试了
string.substring.trim<> ""并且这些都不会在If ... Then上下文中产生正确的布尔值
The string.substring(410,10).trim is equivalent to an empty string, e.g.
"", If you assign string.substring(410,10).trim to a variable, what is in the
variable? What is the length of the variable?

Where is strIn coming from? Does it have ChrW(0) characters in it?

ChrW(0) will make the string appear to be "" in the debugger, when its
actually not, as ChrW(0) is a valid string.

If you run the following what do you see?

Dim strIn As String = New String(" "c, 450)

Dim x As String = strIn.Substring(410, 10).Trim()
Debug.WriteLine(x, "x")
Debug.WriteLine(x.Length, "x.length")

Debug.WriteLine(Not (x.Trim() = ""), "not (x.trim = space)")
Debug.WriteLine(x.Trim() <> "", "x.trim <> space")
Debug.WriteLine(x.Trim() = "", "x.trim = space")

Debug.WriteLine(Not (strIn.Substring(410, 10).Trim() = ""), "not
(substring.trim = space)")
Debug.WriteLine(strIn.Substring(410, 10).Trim() <> "",
"substring.trim <> space")
Debug.WriteLine(strIn.Substring(410, 10).Trim() = "",
"substring.trim = space")

What do you see if you use your original string instead of "New String(" "c,
450)" for strIn?

Hope this helps
Jay
"Darren Anderson" <Da************@discussions.microsoft.com> wrote in
message news:96**********************************@microsof t.com...I have a function that I''ve tried using in an if then statement and I''ve
found that no matter how much reworking I do with the code, the expected
result is incorrect.

the code:

If Not (strIn.Substring(410, 10).Trim = "") Then
''Something processed
Else
''Something processed
End If

The string.substring(410,10).trim is equivelent to an emptry string, e.g.
"", when it comes in. So the expected result is supposed to be TRUE when
you
use (strIn.Substring(410, 10).Trim = ""), and I use the NOT keyword which
negates the true to a false (or vice versa). I can not get this DAMN
function to give me the proper boolean expression, is this a LOGIC bug...

I''ve tried using string.substring.trim = space(?) and I''ve tried
string.substring.trim <> "" and none of these will yield the correct
boolean
value in an If...Then context



" Darren Anderson" <沓************ @ discussions.microsoft.com>写在

消息新闻:96 ********************************** @ microsof t.com ...
"Darren Anderson" <Da************@discussions.microsoft.com> wrote in
message news:96**********************************@microsof t.com...
我有一个功能,我已尝试在if语句中使用
我发现无论我做了多少工作代码,
预期结果不正确。

如果不是(strIn.Substring(410,10).Trim ="")那么
I have a function that I''ve tried using in an if then statement and
I''ve found that no matter how much reworking I do with the code,
the expected result is incorrect.

If Not (strIn.Substring(410, 10).Trim = "") Then




你确定子串包含/ exact / 10 / spaces /?

它们中的任何一个都可以是Null或其他空格字符吗?

Trim()只会删除空格。


strIn /至少/ 419个字符?如果你试图切出一个'不适合源字符串的子字符串,那么VB将会感到沮丧,

,如


" abc" .SubString(2,2)''失败


你是/否/正在使用On Error Resume Next,/ /你?


HTH,

Phill W.



Are you sure the substring contains /exactly/ 10 /spaces/?
Could any of them be Null or other whitespace characters?
Trim() will only remove spaces.

Is strIn /at least/ 419 characters long? VB will get upset if you
try to slice out a substring that''s doesn''t fit within the source string,
as in

"abc".SubString( 2, 2 ) '' fails

You''re /not/ using "On Error Resume Next", /are/ you?

HTH,
Phill W.


这篇关于错误:string.substring.trim =&quot;&quot; (布尔表达式问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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