Console.WriteLine(s)是否缺少线路终结器? [英] Console.WriteLine(s) Is Missing Line Terminator?

查看:85
本文介绍了Console.WriteLine(s)是否缺少线路终结器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个简单的VB代码:


Sub OutputLine(ByRef Level As String,ByRef InfoString As String)

Const gSTDOUT As Integer = -11

Dim hStdOut,BytesWritten As Integer

Dim s As String


s =等级& " " &安培; InfoString

Console.WriteLine(s)

End Sub


这应该将字符串s写入标准输出每行返回

时间。但是,我在这里有两个问题:


1)输出中缺少级别 - 它只包含InfoString。对于

实例:当Level =" INFO"和InforString =" Process started"时,

输出为Process started。只有;

2)最后没有换行符。


关于它发生了什么以及如何解决这个问题的建议?谢谢!

-Emily

解决方案

>


> 1)输出中缺少级别 - 它只包含InfoString。对于
实例:当Level =" INFO"和InforString =" Process started"时,
输出是Process started。只有;
2)最后没有换行符。

关于它发生了什么以及如何解决这个问题的建议?谢谢!



您是否可以发布一个小型的完整应用程序,让我们重现您所看到的行为?b
Console.WriteLine在这里一直很好用

所以我怀疑你的输入不正确。

Mattias


-

Mattias Sj?gren [C#MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。


星期五,2006年11月17日21:46:44 +0100,Mattias Sj?gren写道:


>>
1)输出中缺少级别 - 它只包含InfoString。对于
实例:当Level =" INFO"和InforString =" Process started"时,
输出是Process started。只有;
2)最后没有换行符。

关于它发生了什么以及如何解决这个问题的建议?谢谢!



您是否可以发布一个小型的完整应用程序,让我们重现您所看到的行为?b
Console.WriteLine一直很好用

这里我怀疑你的输入是不正确的。


Mattias



另外,根据经验,避免使用''&''来连接字符串,因为它有隐藏投射错误的b $ ba倾向。它只适用于那里的VB6风格

兼容性,并且应该与选项明确一起烧掉赌注

关闭:)


尝试在Console.WriteLine语句上放置一个断点,看看变量'''''包含什么
。也许你在

结束时传递控制角色?


干杯,

小工具



>另外作为一条经验法则,避免使用''&''来连接字符串,因为它有一个趋势隐藏投射错误。



嗯?你能举个例子吗?那么你建议我们使用

代替?希望不是+运算符。


>它只适用于VB6风格的兼容性,



不,它肯定不是。

Mattias


-

Mattias Sj?gren [ C#MVP] mattias @ mvps.org
http://www.msjogren.net / dotnet / | http://www.dotnetinterop.com

请回复到新闻组。


Hi All,

I have a simple VB code:

Sub OutputLine(ByRef Level As String, ByRef InfoString As String)
Const gSTDOUT As Integer = -11
Dim hStdOut, BytesWritten As Integer
Dim s As String

s = Level & " " & InfoString
Console.WriteLine(s)

End Sub

This should write string s to a standard output with a line return each
time. However, I have two issues here:

1) Level is missing from the output - It only contains InfoString. For
instance: When Level = "INFO", and InforString = "Process started", The
output is "Process started" only;
2) No newline character at the end.

Any advice on what it going on and how to get this resolved? Thanks!
-Emily

解决方案

>

>1) Level is missing from the output - It only contains InfoString. For
instance: When Level = "INFO", and InforString = "Process started", The
output is "Process started" only;
2) No newline character at the end.

Any advice on what it going on and how to get this resolved? Thanks!

Can you post a small complete application that will let us reproduce
the behaviour you''re seeing? Console.WriteLine has always worked fine
here so I suspect your input is incorrect.
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


On Fri, 17 Nov 2006 21:46:44 +0100, Mattias Sj?gren wrote:

>>
1) Level is missing from the output - It only contains InfoString. For
instance: When Level = "INFO", and InforString = "Process started", The
output is "Process started" only;
2) No newline character at the end.

Any advice on what it going on and how to get this resolved? Thanks!


Can you post a small complete application that will let us reproduce
the behaviour you''re seeing? Console.WriteLine has always worked fine
here so I suspect your input is incorrect.
Mattias

Also as a rule of thumb, avoid using ''&'' to concatenate strings, as it has
a tendency to hide casting errors. It''s only in there for VB6 style
compatibility, and should be burned at the stake along with Option Explicit
Off :)

Try placing a breakpoint on the Console.WriteLine statement and see what
the variable ''s'' contains. Perhaps you''re passing control characters on the
end?

Cheers,
Gadget


>Also as a rule of thumb, avoid using ''&'' to concatenate strings, as it has
a tendency to hide casting errors.

Huh? Can you give an example of that? And what do you suggest we use
instead? Hopefully not the + operator.

>It''s only in there for VB6 style compatibility,

No it certainly isn''t.
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


这篇关于Console.WriteLine(s)是否缺少线路终结器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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