Export (0) Print
Expand All

Console.Write Method (String)

Writes the specified string value to the standard output stream.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Public Shared Sub Write ( _
	value As String _
)
'Usage
Dim value As String

Console.Write(value)
public static void Write (
	String value
)
public static function Write (
	value : String
)

Parameters

value

The value to write.

Exception typeCondition

IOException

An I/O error occurred.

If value is a null reference (Nothing in Visual Basic), nothing is written to the standard output stream.

The following code example illustrates the use of the Write method.

Public Class FormatConverter
   Public Shared Sub Main()
      Dim lineInput As String
      lineInput = Console.ReadLine()
      While Not lineInput Is Nothing
         Dim fields() As String = lineInput.Split(ControlChars.Tab)
         Dim isFirstField As Boolean = True
         Dim item As String
         For Each item In  fields
            If isFirstField Then
               isFirstField = False
            Else
               Console.Write(",")
            End If
            ' If the field represents a boolean, replace with a numeric representation.
            Try
               Console.Write(Convert.ToByte(Convert.ToBoolean(item)))
            Catch
               Console.Write(item)
            End Try
         Next item
         Console.WriteLine()
         lineInput = Console.ReadLine()
      End While
   End Sub 'Main
End Class 'FormatConverter

public class FormatConverter
{
    public static void main(String[] args)
    {
        String lineInput;

        while (((lineInput = Console.ReadLine()) != null)) {
            String fields[] = lineInput.Split(new char[] { '\t' });
            boolean isFirstField = true;
            String item = null;
            for (int iCtr = 0; iCtr < fields.length; iCtr++) {
                item = fields[iCtr];
                if (isFirstField) {                
                    isFirstField = false;
                }
                else {                
                    Console.Write(',');
                } 
                // If the field represents a boolean, replace with a numeric 
                // representation.
                try {                
                    Console.Write(Convert.ToByte(Convert.ToBoolean(item)));
                }
                catch (FormatException exp) {                
                    Console.Write(item);
                }
            }
            Console.WriteLine();
        }
    } //main
} //FormatConverter

var lineInput : String;
while ((lineInput = Console.ReadLine()) != null) {
    var fields : String[] = lineInput.Split(char[](['\t']));
    var isFirstField : Boolean = true;
    for(var i in fields) {
        var item = fields[i];
        if (isFirstField)
            isFirstField = false;
        else
            Console.Write(',');
        // If the field represents a boolean, replace with a numeric representation.
        try {
            Console.Write(Convert.ToByte(Convert.ToBoolean(item)));
        }
        catch(FormatException) {
            Console.Write(item);
        }
    }
    Console.WriteLine();
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft