Console.Write Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Grava a representação de texto do valor ou valores especificados no fluxo de saída padrão.
Sobrecargas
Write(String, Object, Object, Object, Object) |
Grava a representação de texto dos objetos especificados e a lista de parâmetros de tamanho variável no fluxo de saída padrão usando as informações de formato especificadas. |
Write(String, Object, Object, Object) |
Grava a representação de texto dos objetos especificados no fluxo de saída padrão usando as informações de formato especificadas. |
Write(Char[], Int32, Int32) |
Grava a submatriz especificada de caracteres Unicode no fluxo de saída padrão. |
Write(String, ReadOnlySpan<Object>) | |
Write(String, Object[]) |
Grava a representação de texto da matriz de objetos especificada, no fluxo de saída padrão usando as informações de formato especificadas. |
Write(String, Object) |
Grava a representação de texto do objeto especificado no fluxo de saída padrão usando as informações de formato especificadas. |
Write(UInt64) |
Grava a representação de texto do valor inteiro sem sinal de 64 bits no fluxo de saída padrão. |
Write(UInt32) |
Grava a representação de texto do valor inteiro sem sinal de 32 bits especificado no fluxo de saída padrão. |
Write(String) |
Grava o valor da cadeia de caracteres especificada no fluxo de saída padrão. |
Write(String, Object, Object) |
Grava a representação de texto dos objetos especificados no fluxo de saída padrão usando as informações de formato especificadas. |
Write(Object) |
Grava a representação de texto do objeto especificado no fluxo de saída padrão. |
Write(Single) |
Grava a representação de texto do valor de ponto flutuante de precisão simples especificado no fluxo de saída padrão. |
Write(Char) |
Grava o valor do caractere Unicode especificado no fluxo de saída padrão. |
Write(Char[]) |
Grava a matriz de caracteres Unicode especificada no fluxo de saída padrão. |
Write(Boolean) |
Grava a representação de texto do valor booliano especificado, no fluxo de saída padrão. |
Write(Double) |
Grava a representação de texto do valor de ponto flutuante de precisão dupla especificado no fluxo de saída padrão. |
Write(Int32) |
Grava a representação de texto do valor inteiro com sinal de 32 bits no fluxo de saída padrão. |
Write(Int64) |
Grava a representação de texto do valor inteiro com sinal de 64 bits no fluxo de saída padrão. |
Write(Decimal) |
Grava a representação de texto do valor Decimal especificado, no fluxo de saída padrão. |
Write(String, Object, Object, Object, Object)
Importante
Esta API não está em conformidade com CLS.
Grava a representação de texto dos objetos especificados e a lista de parâmetros de tamanho variável no fluxo de saída padrão usando as informações de formato especificadas.
public:
static void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2, System::Object ^ arg3);
[System.CLSCompliant(false)]
public static void Write (string format, object arg0, object arg1, object arg2, object arg3);
[<System.CLSCompliant(false)>]
static member Write : string * obj * obj * obj * obj -> unit
Public Shared Sub Write (format As String, arg0 As Object, arg1 As Object, arg2 As Object, arg3 As Object)
Parâmetros
- format
- String
Uma cadeia de caracteres de formato de composição.
- arg0
- Object
O primeiro objeto a ser gravado usando-se format
.
- arg1
- Object
O segundo objeto a ser gravado usando format
.
- arg2
- Object
O terceiro objeto a ser gravado usando-se format
.
- arg3
- Object
O quarto objeto a ser gravado usando format
.
- Atributos
Exceções
Ocorreu um erro de E/S.
format
é null
.
A especificação de formato em format
é inválida.
Exemplos
O exemplo a seguir ilustra o uso de parâmetros variáveis com o Write(String, Object, Object, Object, Object) método . O método é chamado com uma cadeia de caracteres de formato composto e cinco itens de formato.
using namespace System;
//void main(array<System::String ^> ^args)
void main()
{
DateTime dateRecorded(2009, 6, 15);
DateTime startTime(1, 1, 1, 0, 30, 0);
TimeSpan interval(12, 0, 0);
Double temperature1 = 52.8;
Double temperature2 = 63.5;
Console::Write("Date: {0:d}:\n Temperature at {1:t}: {2}\n Temperature at {3:t}: {4}\n",
dateRecorded, startTime, temperature1,
startTime.Add(interval), temperature2);
Console::ReadLine();
}
// The example displays the following output:
// Date: 6/15/2009:
// Temperature at 12:30 AM: 52.8
// Temperature at 12:30 PM: 63.5
Comentários
Observação
Esta API não está em conformidade com CLS. A alternativa compatível com CLS é Console.Write(String, Object[]). Os compiladores C# e Visual Basic resolve automaticamente uma chamada para esse método como uma chamada para Console.Write(String, Object[]).
Esse método usa o recurso de formatação composta do .NET para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.
O parâmetro format
consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.
A sintaxe de um item de formato é {
index[,
alignment][:
formatString]}
, que especifica um índice obrigatório, o comprimento e o alinhamento opcionais do texto formatado e uma cadeia de caracteres opcional de caracteres especificadores de formato que regem como o valor do objeto correspondente é formatado.
O .NET fornece amplo suporte à formatação, que é descrito com mais detalhes nos tópicos de formatação a seguir.
Para obter mais informações sobre o recurso de formatação composta com suporte por métodos como Format, AppendFormate algumas sobrecargas de WriteLine, consulte Formatação composta.
Para obter mais informações sobre especificadores de formato numérico, consulte Cadeias de caracteres de formato numérico padrão e cadeias de caracteres de formato numérico personalizado.
Para obter mais informações sobre especificadores de formato de data e hora, consulte Cadeias de caracteres de formato de data e hora padrão e Cadeias de caracteres de formato de data e hora personalizadas.
Para obter mais informações sobre especificadores de formato de enumeração, consulte Cadeias de caracteres de formato de enumeração.
Para obter mais informações sobre formatação, consulte Tipos de formatação.
Notas aos Chamadores
Esse método é marcado com o palavra-chave, o vararg
que significa que ele dá suporte a um número variável de parâmetros. O método pode ser chamado do Visual C++, mas não pode ser chamado de código C# ou Visual Basic. Os compiladores do C# e do Visual Basic resolve chamadas para Write(String, Object, Object, Object, Object) como chamadas para Write(String, Object[]).
Confira também
Aplica-se a
Write(String, Object, Object, Object)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto dos objetos especificados no fluxo de saída padrão usando as informações de formato especificadas.
public:
static void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1, System::Object ^ arg2);
public static void Write (string format, object? arg0, object? arg1, object? arg2);
public static void Write (string format, object arg0, object arg1, object arg2);
static member Write : string * obj * obj * obj -> unit
Public Shared Sub Write (format As String, arg0 As Object, arg1 As Object, arg2 As Object)
Parâmetros
- format
- String
Uma cadeia de caracteres de formato de composição.
- arg0
- Object
O primeiro objeto a ser gravado usando-se format
.
- arg1
- Object
O segundo objeto a ser gravado usando format
.
- arg2
- Object
O terceiro objeto a ser gravado usando-se format
.
Exceções
Ocorreu um erro de E/S.
format
é null
.
A especificação de formato em format
é inválida.
Exemplos
O exemplo a seguir usa o método WriteLine
para demonstrar os especificadores de formatação padrão para números, datas e enumerações.
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using namespace System;
public enum class Color {Yellow = 1, Blue, Green};
int main()
{
DateTime thisDate = DateTime::Now;
Console::Clear();
// Format a negative integer or floating-point number in various ways.
Console::WriteLine("Standard Numeric Format Specifiers");
Console::WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f);
// Format the current date in various ways.
Console::WriteLine("Standard DateTime Format Specifiers");
Console::WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console::WriteLine("Standard Enumeration Format Specifiers");
Console::WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color::Green);
};
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using System;
class Sample
{
enum Color {Yellow = 1, Blue, Green};
static DateTime thisDate = DateTime.Now;
public static void Main()
{
Console.Clear();
// Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers");
Console.WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f);
// Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers");
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers");
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green);
}
}
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
open System
type Color =
| Yellow = 1
| Blue = 2
| Green = 3
let thisDate = DateTime.Now
Console.Clear()
// Format a negative integer or floating-point number in various ways.
Console.WriteLine "Standard Numeric Format Specifiers"
Console.WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f)
// Format the current date in various ways.
Console.WriteLine "Standard DateTime Format Specifiers"
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate)
// Format a Color enumeration value in various ways.
Console.WriteLine "Standard Enumeration Format Specifiers"
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green)
// This code example produces the following results:
//
// Standard Numeric Format Specifiers
// (C) Currency: . . . . . . . . ($123.00)
// (D) Decimal:. . . . . . . . . -123
// (E) Scientific: . . . . . . . -1.234500E+002
// (F) Fixed point:. . . . . . . -123.45
// (G) General:. . . . . . . . . -123
// (default):. . . . . . . . -123 (default = 'G')
// (N) Number: . . . . . . . . . -123.00
// (P) Percent:. . . . . . . . . -12,345.00 %
// (R) Round-trip: . . . . . . . -123.45
// (X) Hexadecimal:. . . . . . . FFFFFF85
//
// Standard DateTime Format Specifiers
// (d) Short date: . . . . . . . 6/26/2004
// (D) Long date:. . . . . . . . Saturday, June 26, 2004
// (t) Short time: . . . . . . . 8:11 PM
// (T) Long time:. . . . . . . . 8:11:04 PM
// (f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
// (F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
// (g) General date/short time:. 6/26/2004 8:11 PM
// (G) General date/long time: . 6/26/2004 8:11:04 PM
// (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
// (M) Month:. . . . . . . . . . June 26
// (R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
// (s) Sortable: . . . . . . . . 2004-06-26T20:11:04
// (u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
// (U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
// (Y) Year: . . . . . . . . . . June, 2004
//
// Standard Enumeration Format Specifiers
// (G) General:. . . . . . . . . Green
// (default):. . . . . . . . Green (default = 'G')
// (F) Flags:. . . . . . . . . . Green (flags or integer)
// (D) Decimal number: . . . . . 3
// (X) Hexadecimal:. . . . . . . 00000003
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.
Class Sample
Public Enum Color
Yellow = 1
Blue = 2
Green = 3
End Enum 'Color
Private Shared thisDate As DateTime = DateTime.Now
Public Shared Sub Main()
Console.Clear()
' Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers")
Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
"(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
"(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
"(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
"(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
"(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
"(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
- 123, - 123.45F)
' Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers")
Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
"(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
"(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
"(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
"(f) Full date/short time: . . {0:f}" & vbCrLf & _
"(F) Full date/long time:. . . {0:F}" & vbCrLf & _
"(g) General date/short time:. {0:g}" & vbCrLf & _
"(G) General date/long time: . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
"(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
"(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
"(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
"(U) Universal full date/time: {0:U}" & vbCrLf & _
"(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
thisDate)
' Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers")
Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
"(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
Color.Green)
End Sub
End Class
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
' (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
' (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
' (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003
'
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
Esse método usa o recurso de formatação composta do .NET para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.
O parâmetro format
consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.
A sintaxe de um item de formato é {
index[,
alignment][:
formatString]}
, que especifica um índice obrigatório, o comprimento e o alinhamento opcionais do texto formatado e uma cadeia de caracteres opcional de caracteres especificadores de formato que regem como o valor do objeto correspondente é formatado.
O .NET fornece amplo suporte à formatação, que é descrito com mais detalhes nos tópicos de formatação a seguir.
Para obter mais informações sobre o recurso de formatação composta com suporte por métodos como Format, AppendFormate algumas sobrecargas de WriteLine, consulte Formatação composta.
Para obter mais informações sobre especificadores de formato numérico, consulte Cadeias de caracteres de formato numérico padrão e cadeias de caracteres de formato numérico personalizado.
Para obter mais informações sobre especificadores de formato de data e hora, consulte Cadeias de caracteres de formato de data e hora padrão e Cadeias de caracteres de formato de data e hora personalizadas.
Para obter mais informações sobre especificadores de formato de enumeração, consulte Cadeias de caracteres de formato de enumeração.
Para obter mais informações sobre formatação, consulte Tipos de formatação.
Confira também
Aplica-se a
Write(Char[], Int32, Int32)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a submatriz especificada de caracteres Unicode no fluxo de saída padrão.
public:
static void Write(cli::array <char> ^ buffer, int index, int count);
public static void Write (char[] buffer, int index, int count);
static member Write : char[] * int * int -> unit
Public Shared Sub Write (buffer As Char(), index As Integer, count As Integer)
Parâmetros
- buffer
- Char[]
Uma matriz de caracteres Unicode.
- index
- Int32
A posição inicial em buffer
.
- count
- Int32
O número de caracteres a serem gravados.
Exceções
buffer
é null
.
index
ou count
é menor que zero.
A soma de index
e count
especifica uma posição que não está no buffer
.
Ocorreu um erro de E/S.
Comentários
Esse método grava caracteres count
começando na posição index
de no fluxo de buffer
saída padrão.
Confira também
Aplica-se a
Write(String, ReadOnlySpan<Object>)
public:
static void Write(System::String ^ format, ReadOnlySpan<System::Object ^> arg);
public static void Write (string format, scoped ReadOnlySpan<object?> arg);
static member Write : string * ReadOnlySpan<obj> -> unit
Public Shared Sub Write (format As String, arg As ReadOnlySpan(Of Object))
Parâmetros
- format
- String
- arg
- ReadOnlySpan<Object>
Aplica-se a
Write(String, Object[])
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto da matriz de objetos especificada, no fluxo de saída padrão usando as informações de formato especificadas.
public:
static void Write(System::String ^ format, ... cli::array <System::Object ^> ^ arg);
public static void Write (string format, params object?[]? arg);
public static void Write (string format, params object[] arg);
static member Write : string * obj[] -> unit
Public Shared Sub Write (format As String, ParamArray arg As Object())
Parâmetros
- format
- String
Uma cadeia de caracteres de formato de composição.
- arg
- Object[]
Uma matriz de objetos a ser gravada usando format
.
Exceções
Ocorreu um erro de E/S.
format
ou arg
é null
.
A especificação de formato em format
é inválida.
Exemplos
O exemplo a seguir define uma Person
classe com várias propriedades que fornecem informações sobre uma pessoa. Seu GetDescription
método retorna uma matriz que contém todos os valores de propriedade, exceto um. Em seguida, o exemplo usa a matriz retornada pelo GetDescription
método para exibir os valores do objeto Person.
using System;
public class Person
{
public String Name { get; set; }
public DateTime BirthDate { get; set; }
public Double Height { get; set; }
public Double Weight { get; set; }
public Char Gender { get; set; }
public String Remarks { get; set; }
public object[] GetDescription()
{
return new object[] { Name, Gender, Height, Weight, BirthDate};
}
}
public class Example
{
public static void Main()
{
var p1 = new Person() { Name = "John", Gender = 'M',
BirthDate = new DateTime(1992, 5, 10),
Height = 73.5, Weight = 207 };
p1.Remarks = "Client since 1/3/2012";
Console.Write("{0}: {1}, born {4:d} Height {2} inches, Weight {3} lbs ",
p1.GetDescription());
if (String.IsNullOrEmpty(p1.Remarks))
Console.WriteLine();
else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth ?
"\n " : "");
}
}
// The example displays the following output:
// John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
open System
type Person =
{ Name: string
BirthDate: DateOnly
Height: double
Weight: double
Gender: char
Remarks: string }
member this.GetDescription(): obj [] =
[| this.Name; this.Gender; this.Height; this.Weight; this.BirthDate |]
let p1 =
{ Name = "John"
Gender = 'M'
BirthDate = DateOnly(1992, 5, 10)
Height = 73.5
Weight = 207
Remarks = "Client since 1/3/2012" }
Console.Write("{0}: {1}, born {4:d} Height {2} inches, Weight {3} lbs ", p1.GetDescription())
if String.IsNullOrEmpty p1.Remarks then
Console.WriteLine()
else
Console.WriteLine $"""{if Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth then "\n " else ""}Remarks: {p1.Remarks}"""
// The example displays the following output:
// John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
Public Class Person
Public Property Name As String
Public Property BirthDate As DateTime
Public Property Height As Double
Public Property Weight As Double
Public Property Gender As Char
Public Property Remarks As String
Public Function GetDescription() As Object()
Return { Name, Gender, Height, Weight, BirthDate}
End Function
End Class
Module Example
Public Sub Main()
Dim p1 As New Person() With { .Name = "John", .Gender = "M"c,
.BirthDate = New DateTime(1992, 5, 10),
.Height = 73.5, .Weight = 207 }
p1.Remarks = "Client since 1/3/2012"
Console.Write("{0}: {1}, born {4:d} Height {2} inches, Weight {3} lbs ",
p1.GetDescription())
If String.IsNullOrEmpty(p1.Remarks) Then
Console.WriteLine()
Else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
If(Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth,
vbCrLf + " ", ""))
End If
End Sub
End Module
' The example displays the following output:
' John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
Observe que o exemplo chama o Write(String, Object[]) método em vez do WriteLine(String, Object[]) método porque ele tenta exibir o valor da Person.Remarks
propriedade na mesma linha. Para fazer isso, ele examina o valor das CursorLeft propriedades e WindowWidth para determinar se há espaço suficiente para a observação se ajustar. Se houver, ele exibirá a linha. Caso contrário, ele grava uma linha, recuará três espaços e exibirá o comentário.
O exemplo a seguir é idêntico ao primeiro, exceto que ele fornece uma lista de cinco itens como o arg
argumento em vez de uma matriz de parâmetros.
using System;
public class Person
{
public String Name { get; set; }
public DateTime BirthDate { get; set; }
public Double Height { get; set; }
public Double Weight { get; set; }
public Char Gender { get; set; }
public String Remarks { get; set; }
public object[] GetDescription()
{
return new object[] { Name, Gender, Height, Weight, BirthDate};
}
}
public class Example
{
public static void Main()
{
var p1 = new Person() { Name = "John", Gender = 'M',
BirthDate = new DateTime(1992, 5, 10),
Height = 73.5, Weight = 207 };
p1.Remarks = "Client since 1/3/2012";
Console.Write("{0}: {1}, born {2:d} Height {3} inches, Weight {4} lbs ",
p1.Name, p1.Gender, p1.BirthDate, p1.Height, p1.Weight);
if (String.IsNullOrEmpty(p1.Remarks))
Console.WriteLine();
else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth ?
"\n " : "");
}
}
// The example displays the following output:
// John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
open System
type Person =
{ Name: string
BirthDate: DateOnly
Height: double
Weight: double
Gender: char
Remarks: string }
member this.GetDescription(): obj [] =
[| this.Name; this.Gender; this.Height; this.Weight; this.BirthDate |]
let p1 =
{ Name = "John"
Gender = 'M'
BirthDate = DateOnly(1992, 5, 10)
Height = 73.5
Weight = 207
Remarks = "Client since 1/3/2012" }
printf $"{p1.Name}: {p1.Gender}, born {p1.BirthDate:d} Height {p1.Height} inches, Weight {p1.Weight} lbs "
if String.IsNullOrEmpty p1.Remarks then
Console.WriteLine()
else
Console.WriteLine $"""{if Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth then "\n " else ""}Remarks: {p1.Remarks}"""
// The example displays the following output:
// John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
Public Class Person
Public Property Name As String
Public Property BirthDate As DateTime
Public Property Height As Double
Public Property Weight As Double
Public Property Gender As Char
Public Property Remarks As String
Public Function GetDescription() As Object()
Return { Name, Gender, Height, Weight, BirthDate}
End Function
End Class
Module Example
Public Sub Main()
Dim p1 As New Person() With { .Name = "John", .Gender = "M"c,
.BirthDate = New DateTime(1992, 5, 10),
.Height = 73.5, .Weight = 207 }
p1.Remarks = "Client since 1/3/2012"
Console.Write("{0}: {1}, born {2:d} Height {3} inches, Weight {4} lbs ",
p1.Name, p1.Gender, p1.BirthDate, p1.Height, p1.Weight)
If String.IsNullOrEmpty(p1.Remarks) Then
Console.WriteLine()
Else
Console.WriteLine("{1}Remarks: {0}", p1.Remarks,
If(Console.CursorLeft + p1.Remarks.Length + 10 > Console.WindowWidth,
vbCrLf + " ", ""))
End If
End Sub
End Module
' The example displays the following output:
' John: M, born 5/10/1992 Height 73.5 inches, Weight 207 lbs Remarks: Client since 1/3/2012
Comentários
Esse método usa o recurso de formatação composta do .NET para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.
O parâmetro format
consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.
A sintaxe de um item de formato é {
index[,
alignment][:
formatString]}
, que especifica um índice obrigatório, o comprimento e o alinhamento opcionais do texto formatado e uma cadeia de caracteres opcional de caracteres especificadores de formato que regem como o valor do objeto correspondente é formatado.
O .NET fornece amplo suporte à formatação, que é descrito com mais detalhes nos tópicos de formatação a seguir.
Para obter mais informações sobre o recurso de formatação composta com suporte por métodos como Format, AppendFormate algumas sobrecargas de WriteLine, consulte Formatação composta.
Para obter mais informações sobre especificadores de formato numérico, consulte Cadeias de caracteres de formato numérico padrão e cadeias de caracteres de formato numérico personalizado.
Para obter mais informações sobre especificadores de formato de data e hora, consulte Cadeias de caracteres de formato de data e hora padrão e Cadeias de caracteres de formato de data e hora personalizadas.
Para obter mais informações sobre especificadores de formato de enumeração, consulte Cadeias de caracteres de formato de enumeração.
Para obter mais informações sobre formatação, consulte Tipos de formatação.
O arg
parâmetro é uma matriz de parâmetros. Os argumentos podem ser passados para o método como uma matriz ou como uma lista de cinco ou mais itens. Os exemplos ilustram ambas as formas de chamada de método.
Notas aos Chamadores
Esse método não é chamado pelo código C++. O compilador C++ resolve chamadas para System.Console.Write que incluem uma cadeia de caracteres e uma lista de quatro ou mais parâmetros de objeto como uma chamada para Write(String, Object, Object, Object, Object). Ele resolve chamadas para System.Console.Write que incluem uma cadeia de caracteres e uma matriz de objetos como uma chamada para Write(String, Object).
Confira também
Aplica-se a
Write(String, Object)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto do objeto especificado no fluxo de saída padrão usando as informações de formato especificadas.
public:
static void Write(System::String ^ format, System::Object ^ arg0);
public static void Write (string format, object? arg0);
public static void Write (string format, object arg0);
static member Write : string * obj -> unit
Public Shared Sub Write (format As String, arg0 As Object)
Parâmetros
- format
- String
Uma cadeia de caracteres de formato de composição.
- arg0
- Object
Um objeto a ser gravado com o uso de format
.
Exceções
Ocorreu um erro de E/S.
format
é null
.
A especificação de formato em format
é inválida.
Exemplos
O exemplo a seguir usa o método WriteLine
para demonstrar os especificadores de formatação padrão para números, datas e enumerações.
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using namespace System;
public enum class Color {Yellow = 1, Blue, Green};
int main()
{
DateTime thisDate = DateTime::Now;
Console::Clear();
// Format a negative integer or floating-point number in various ways.
Console::WriteLine("Standard Numeric Format Specifiers");
Console::WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f);
// Format the current date in various ways.
Console::WriteLine("Standard DateTime Format Specifiers");
Console::WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console::WriteLine("Standard Enumeration Format Specifiers");
Console::WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color::Green);
};
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using System;
class Sample
{
enum Color {Yellow = 1, Blue, Green};
static DateTime thisDate = DateTime.Now;
public static void Main()
{
Console.Clear();
// Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers");
Console.WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f);
// Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers");
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers");
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green);
}
}
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
open System
type Color =
| Yellow = 1
| Blue = 2
| Green = 3
let thisDate = DateTime.Now
Console.Clear()
// Format a negative integer or floating-point number in various ways.
Console.WriteLine "Standard Numeric Format Specifiers"
Console.WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f)
// Format the current date in various ways.
Console.WriteLine "Standard DateTime Format Specifiers"
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate)
// Format a Color enumeration value in various ways.
Console.WriteLine "Standard Enumeration Format Specifiers"
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green)
// This code example produces the following results:
//
// Standard Numeric Format Specifiers
// (C) Currency: . . . . . . . . ($123.00)
// (D) Decimal:. . . . . . . . . -123
// (E) Scientific: . . . . . . . -1.234500E+002
// (F) Fixed point:. . . . . . . -123.45
// (G) General:. . . . . . . . . -123
// (default):. . . . . . . . -123 (default = 'G')
// (N) Number: . . . . . . . . . -123.00
// (P) Percent:. . . . . . . . . -12,345.00 %
// (R) Round-trip: . . . . . . . -123.45
// (X) Hexadecimal:. . . . . . . FFFFFF85
//
// Standard DateTime Format Specifiers
// (d) Short date: . . . . . . . 6/26/2004
// (D) Long date:. . . . . . . . Saturday, June 26, 2004
// (t) Short time: . . . . . . . 8:11 PM
// (T) Long time:. . . . . . . . 8:11:04 PM
// (f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
// (F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
// (g) General date/short time:. 6/26/2004 8:11 PM
// (G) General date/long time: . 6/26/2004 8:11:04 PM
// (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
// (M) Month:. . . . . . . . . . June 26
// (R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
// (s) Sortable: . . . . . . . . 2004-06-26T20:11:04
// (u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
// (U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
// (Y) Year: . . . . . . . . . . June, 2004
//
// Standard Enumeration Format Specifiers
// (G) General:. . . . . . . . . Green
// (default):. . . . . . . . Green (default = 'G')
// (F) Flags:. . . . . . . . . . Green (flags or integer)
// (D) Decimal number: . . . . . 3
// (X) Hexadecimal:. . . . . . . 00000003
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.
Class Sample
Public Enum Color
Yellow = 1
Blue = 2
Green = 3
End Enum 'Color
Private Shared thisDate As DateTime = DateTime.Now
Public Shared Sub Main()
Console.Clear()
' Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers")
Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
"(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
"(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
"(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
"(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
"(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
"(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
- 123, - 123.45F)
' Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers")
Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
"(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
"(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
"(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
"(f) Full date/short time: . . {0:f}" & vbCrLf & _
"(F) Full date/long time:. . . {0:F}" & vbCrLf & _
"(g) General date/short time:. {0:g}" & vbCrLf & _
"(G) General date/long time: . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
"(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
"(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
"(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
"(U) Universal full date/time: {0:U}" & vbCrLf & _
"(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
thisDate)
' Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers")
Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
"(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
Color.Green)
End Sub
End Class
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
' (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
' (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
' (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003
'
O exemplo a seguir ilustra o uso do método Write.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
Esse método usa o recurso de formatação composta do .NET para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.
O parâmetro format
consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.
A sintaxe de um item de formato é {
index[,
alignment][:
formatString]}
, que especifica um índice obrigatório, o comprimento e o alinhamento opcionais do texto formatado e uma cadeia de caracteres opcional de caracteres especificadores de formato que regem como o valor do objeto correspondente é formatado.
O .NET fornece amplo suporte à formatação, que é descrito com mais detalhes nos tópicos de formatação a seguir.
Para obter mais informações sobre o recurso de formatação composta com suporte por métodos como Format, AppendFormate algumas sobrecargas de WriteLine, consulte Formatação composta.
Para obter mais informações sobre especificadores de formato numérico, consulte Cadeias de caracteres de formato numérico padrão e cadeias de caracteres de formato numérico personalizado.
Para obter mais informações sobre especificadores de formato de data e hora, consulte Cadeias de caracteres de formato de data e hora padrão e Cadeias de caracteres de formato de data e hora personalizadas.
Para obter mais informações sobre especificadores de formato de enumeração, consulte Cadeias de caracteres de formato de enumeração.
Para obter mais informações sobre formatação, consulte Tipos de formatação.
Confira também
Aplica-se a
Write(UInt64)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Importante
Esta API não está em conformidade com CLS.
Grava a representação de texto do valor inteiro sem sinal de 64 bits no fluxo de saída padrão.
public:
static void Write(System::UInt64 value);
[System.CLSCompliant(false)]
public static void Write (ulong value);
[<System.CLSCompliant(false)>]
static member Write : uint64 -> unit
Public Shared Sub Write (value As ULong)
Parâmetros
- value
- UInt64
O valor a ser gravado.
- Atributos
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
A representação de texto de value
é produzida chamando o UInt64.ToString método .
Confira também
Aplica-se a
Write(UInt32)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Importante
Esta API não está em conformidade com CLS.
Grava a representação de texto do valor inteiro sem sinal de 32 bits especificado no fluxo de saída padrão.
public:
static void Write(System::UInt32 value);
[System.CLSCompliant(false)]
public static void Write (uint value);
[<System.CLSCompliant(false)>]
static member Write : uint32 -> unit
Public Shared Sub Write (value As UInteger)
Parâmetros
- value
- UInt32
O valor a ser gravado.
- Atributos
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
A representação de texto de value
é produzida chamando o UInt32.ToString método .
Confira também
Aplica-se a
Write(String)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava o valor da cadeia de caracteres especificada no fluxo de saída padrão.
public:
static void Write(System::String ^ value);
public static void Write (string? value);
public static void Write (string value);
static member Write : string -> unit
Public Shared Sub Write (value As String)
Parâmetros
- value
- String
O valor a ser gravado.
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
Se value for null
, nada será gravado no fluxo de saída padrão.
Confira também
Aplica-se a
Write(String, Object, Object)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto dos objetos especificados no fluxo de saída padrão usando as informações de formato especificadas.
public:
static void Write(System::String ^ format, System::Object ^ arg0, System::Object ^ arg1);
public static void Write (string format, object? arg0, object? arg1);
public static void Write (string format, object arg0, object arg1);
static member Write : string * obj * obj -> unit
Public Shared Sub Write (format As String, arg0 As Object, arg1 As Object)
Parâmetros
- format
- String
Uma cadeia de caracteres de formato de composição.
- arg0
- Object
O primeiro objeto a ser gravado usando-se format
.
- arg1
- Object
O segundo objeto a ser gravado usando format
.
Exceções
Ocorreu um erro de E/S.
format
é null
.
A especificação de formato em format
é inválida.
Exemplos
O exemplo a seguir usa o método WriteLine
para demonstrar os especificadores de formatação padrão para números, datas e enumerações.
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using namespace System;
public enum class Color {Yellow = 1, Blue, Green};
int main()
{
DateTime thisDate = DateTime::Now;
Console::Clear();
// Format a negative integer or floating-point number in various ways.
Console::WriteLine("Standard Numeric Format Specifiers");
Console::WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f);
// Format the current date in various ways.
Console::WriteLine("Standard DateTime Format Specifiers");
Console::WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console::WriteLine("Standard Enumeration Format Specifiers");
Console::WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color::Green);
};
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
using System;
class Sample
{
enum Color {Yellow = 1, Blue, Green};
static DateTime thisDate = DateTime.Now;
public static void Main()
{
Console.Clear();
// Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers");
Console.WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f);
// Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers");
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate);
// Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers");
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green);
}
}
/*
This code example produces the following results:
Standard Numeric Format Specifiers
(C) Currency: . . . . . . . . ($123.00)
(D) Decimal:. . . . . . . . . -123
(E) Scientific: . . . . . . . -1.234500E+002
(F) Fixed point:. . . . . . . -123.45
(G) General:. . . . . . . . . -123
(default):. . . . . . . . -123 (default = 'G')
(N) Number: . . . . . . . . . -123.00
(P) Percent:. . . . . . . . . -12,345.00 %
(R) Round-trip: . . . . . . . -123.45
(X) Hexadecimal:. . . . . . . FFFFFF85
Standard DateTime Format Specifiers
(d) Short date: . . . . . . . 6/26/2004
(D) Long date:. . . . . . . . Saturday, June 26, 2004
(t) Short time: . . . . . . . 8:11 PM
(T) Long time:. . . . . . . . 8:11:04 PM
(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
(g) General date/short time:. 6/26/2004 8:11 PM
(G) General date/long time: . 6/26/2004 8:11:04 PM
(default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
(M) Month:. . . . . . . . . . June 26
(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
(Y) Year: . . . . . . . . . . June, 2004
Standard Enumeration Format Specifiers
(G) General:. . . . . . . . . Green
(default):. . . . . . . . Green (default = 'G')
(F) Flags:. . . . . . . . . . Green (flags or integer)
(D) Decimal number: . . . . . 3
(X) Hexadecimal:. . . . . . . 00000003
*/
// This code example demonstrates the Console.WriteLine() method.
// Formatting for this example uses the "en-US" culture.
open System
type Color =
| Yellow = 1
| Blue = 2
| Green = 3
let thisDate = DateTime.Now
Console.Clear()
// Format a negative integer or floating-point number in various ways.
Console.WriteLine "Standard Numeric Format Specifiers"
Console.WriteLine(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f)
// Format the current date in various ways.
Console.WriteLine "Standard DateTime Format Specifiers"
Console.WriteLine(
"(d) Short date: . . . . . . . {0:d}\n" +
"(D) Long date:. . . . . . . . {0:D}\n" +
"(t) Short time: . . . . . . . {0:t}\n" +
"(T) Long time:. . . . . . . . {0:T}\n" +
"(f) Full date/short time: . . {0:f}\n" +
"(F) Full date/long time:. . . {0:F}\n" +
"(g) General date/short time:. {0:g}\n" +
"(G) General date/long time: . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(M) Month:. . . . . . . . . . {0:M}\n" +
"(R) RFC1123:. . . . . . . . . {0:R}\n" +
"(s) Sortable: . . . . . . . . {0:s}\n" +
"(u) Universal sortable: . . . {0:u} (invariant)\n" +
"(U) Universal full date/time: {0:U}\n" +
"(Y) Year: . . . . . . . . . . {0:Y}\n",
thisDate)
// Format a Color enumeration value in various ways.
Console.WriteLine "Standard Enumeration Format Specifiers"
Console.WriteLine(
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)\n" +
"(D) Decimal number: . . . . . {0:D}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
Color.Green)
// This code example produces the following results:
//
// Standard Numeric Format Specifiers
// (C) Currency: . . . . . . . . ($123.00)
// (D) Decimal:. . . . . . . . . -123
// (E) Scientific: . . . . . . . -1.234500E+002
// (F) Fixed point:. . . . . . . -123.45
// (G) General:. . . . . . . . . -123
// (default):. . . . . . . . -123 (default = 'G')
// (N) Number: . . . . . . . . . -123.00
// (P) Percent:. . . . . . . . . -12,345.00 %
// (R) Round-trip: . . . . . . . -123.45
// (X) Hexadecimal:. . . . . . . FFFFFF85
//
// Standard DateTime Format Specifiers
// (d) Short date: . . . . . . . 6/26/2004
// (D) Long date:. . . . . . . . Saturday, June 26, 2004
// (t) Short time: . . . . . . . 8:11 PM
// (T) Long time:. . . . . . . . 8:11:04 PM
// (f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
// (F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
// (g) General date/short time:. 6/26/2004 8:11 PM
// (G) General date/long time: . 6/26/2004 8:11:04 PM
// (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
// (M) Month:. . . . . . . . . . June 26
// (R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
// (s) Sortable: . . . . . . . . 2004-06-26T20:11:04
// (u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
// (U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
// (Y) Year: . . . . . . . . . . June, 2004
//
// Standard Enumeration Format Specifiers
// (G) General:. . . . . . . . . Green
// (default):. . . . . . . . Green (default = 'G')
// (F) Flags:. . . . . . . . . . Green (flags or integer)
// (D) Decimal number: . . . . . 3
// (X) Hexadecimal:. . . . . . . 00000003
' This code example demonstrates the Console.WriteLine() method.
' Formatting for this example uses the "en-US" culture.
Class Sample
Public Enum Color
Yellow = 1
Blue = 2
Green = 3
End Enum 'Color
Private Shared thisDate As DateTime = DateTime.Now
Public Shared Sub Main()
Console.Clear()
' Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers")
Console.WriteLine("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
"(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
"(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
"(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
"(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
"(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
"(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
- 123, - 123.45F)
' Format the current date in various ways.
Console.WriteLine("Standard DateTime Format Specifiers")
Console.WriteLine("(d) Short date: . . . . . . . {0:d}" & vbCrLf & _
"(D) Long date:. . . . . . . . {0:D}" & vbCrLf & _
"(t) Short time: . . . . . . . {0:t}" & vbCrLf & _
"(T) Long time:. . . . . . . . {0:T}" & vbCrLf & _
"(f) Full date/short time: . . {0:f}" & vbCrLf & _
"(F) Full date/long time:. . . {0:F}" & vbCrLf & _
"(g) General date/short time:. {0:g}" & vbCrLf & _
"(G) General date/long time: . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(M) Month:. . . . . . . . . . {0:M}" & vbCrLf & _
"(R) RFC1123:. . . . . . . . . {0:R}" & vbCrLf & _
"(s) Sortable: . . . . . . . . {0:s}" & vbCrLf & _
"(u) Universal sortable: . . . {0:u} (invariant)" & vbCrLf & _
"(U) Universal full date/time: {0:U}" & vbCrLf & _
"(Y) Year: . . . . . . . . . . {0:Y}" & vbCrLf, _
thisDate)
' Format a Color enumeration value in various ways.
Console.WriteLine("Standard Enumeration Format Specifiers")
Console.WriteLine("(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(F) Flags:. . . . . . . . . . {0:F} (flags or integer)" & vbCrLf & _
"(D) Decimal number: . . . . . {0:D}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
Color.Green)
End Sub
End Class
'
'This code example produces the following results:
'
'Standard Numeric Format Specifiers
'(C) Currency: . . . . . . . . ($123.00)
'(D) Decimal:. . . . . . . . . -123
'(E) Scientific: . . . . . . . -1.234500E+002
'(F) Fixed point:. . . . . . . -123.45
'(G) General:. . . . . . . . . -123
' (default):. . . . . . . . -123 (default = 'G')
'(N) Number: . . . . . . . . . -123.00
'(P) Percent:. . . . . . . . . -12,345.00 %
'(R) Round-trip: . . . . . . . -123.45
'(X) Hexadecimal:. . . . . . . FFFFFF85
'
'Standard DateTime Format Specifiers
'(d) Short date: . . . . . . . 6/26/2004
'(D) Long date:. . . . . . . . Saturday, June 26, 2004
'(t) Short time: . . . . . . . 8:11 PM
'(T) Long time:. . . . . . . . 8:11:04 PM
'(f) Full date/short time: . . Saturday, June 26, 2004 8:11 PM
'(F) Full date/long time:. . . Saturday, June 26, 2004 8:11:04 PM
'(g) General date/short time:. 6/26/2004 8:11 PM
'(G) General date/long time: . 6/26/2004 8:11:04 PM
' (default):. . . . . . . . 6/26/2004 8:11:04 PM (default = 'G')
'(M) Month:. . . . . . . . . . June 26
'(R) RFC1123:. . . . . . . . . Sat, 26 Jun 2004 20:11:04 GMT
'(s) Sortable: . . . . . . . . 2004-06-26T20:11:04
'(u) Universal sortable: . . . 2004-06-26 20:11:04Z (invariant)
'(U) Universal full date/time: Sunday, June 27, 2004 3:11:04 AM
'(Y) Year: . . . . . . . . . . June, 2004
'
'Standard Enumeration Format Specifiers
'(G) General:. . . . . . . . . Green
' (default):. . . . . . . . Green (default = 'G')
'(F) Flags:. . . . . . . . . . Green (flags or integer)
'(D) Decimal number: . . . . . 3
'(X) Hexadecimal:. . . . . . . 00000003
'
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
Esse método usa o recurso de formatação composta do .NET para converter o valor de um objeto em sua representação de texto e inserir essa representação em uma cadeia de caracteres. A cadeia de caracteres resultante é gravada no fluxo de saída.
O parâmetro format
consiste em zero ou mais execuções de texto combinadas com zero ou mais espaços reservados indexados, chamados de itens de formato, que correspondem a um objeto na lista de parâmetros desse método. O processo de formatação substitui cada item de formato pela representação de texto do valor do objeto correspondente.
A sintaxe de um item de formato é {
index[,
alignment][:
formatString]}
, que especifica um índice obrigatório, o comprimento e o alinhamento opcionais do texto formatado e uma cadeia de caracteres opcional de caracteres especificadores de formato que regem como o valor do objeto correspondente é formatado.
O .NET fornece amplo suporte à formatação, que é descrito com mais detalhes nos tópicos de formatação a seguir.
Para obter mais informações sobre o recurso de formatação composta com suporte por métodos como Format, AppendFormate algumas sobrecargas de WriteLine, consulte Formatação composta.
Para obter mais informações sobre especificadores de formato numérico, consulte Cadeias de caracteres de formato numérico padrão e cadeias de caracteres de formato numérico personalizado.
Para obter mais informações sobre especificadores de formato de data e hora, consulte Cadeias de caracteres de formato de data e hora padrão e Cadeias de caracteres de formato de data e hora personalizadas.
Para obter mais informações sobre especificadores de formato de enumeração, consulte Cadeias de caracteres de formato de enumeração.
Para obter mais informações sobre formatação, consulte Tipos de formatação.
Confira também
Aplica-se a
Write(Object)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto do objeto especificado no fluxo de saída padrão.
public:
static void Write(System::Object ^ value);
public static void Write (object? value);
public static void Write (object value);
static member Write : obj -> unit
Public Shared Sub Write (value As Object)
Parâmetros
- value
- Object
O valor a ser gravado ou null
.
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
Se value
for null
, nada será gravado e nenhuma exceção será gerada. Caso contrário, o ToString
método de value
é chamado para produzir sua representação de cadeia de caracteres e a cadeia de caracteres resultante é gravada no fluxo de saída padrão.
Confira também
Aplica-se a
Write(Single)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto do valor de ponto flutuante de precisão simples especificado no fluxo de saída padrão.
public:
static void Write(float value);
public static void Write (float value);
static member Write : single -> unit
Public Shared Sub Write (value As Single)
Parâmetros
- value
- Single
O valor a ser gravado.
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
A representação de texto de value
é produzida chamando o Single.ToString método .
Confira também
Aplica-se a
Write(Char)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava o valor do caractere Unicode especificado no fluxo de saída padrão.
public:
static void Write(char value);
public static void Write (char value);
static member Write : char -> unit
Public Shared Sub Write (value As Char)
Parâmetros
- value
- Char
O valor a ser gravado.
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Confira também
Aplica-se a
Write(Char[])
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a matriz de caracteres Unicode especificada no fluxo de saída padrão.
public:
static void Write(cli::array <char> ^ buffer);
public static void Write (char[]? buffer);
public static void Write (char[] buffer);
static member Write : char[] -> unit
Public Shared Sub Write (buffer As Char())
Parâmetros
- buffer
- Char[]
Uma matriz de caracteres Unicode.
Exceções
Ocorreu um erro de E/S.
Confira também
Aplica-se a
Write(Boolean)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto do valor booliano especificado, no fluxo de saída padrão.
public:
static void Write(bool value);
public static void Write (bool value);
static member Write : bool -> unit
Public Shared Sub Write (value As Boolean)
Parâmetros
- value
- Boolean
O valor a ser gravado.
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
A representação de texto de value
é produzida chamando Boolean.ToString, que gera ou Boolean.TrueStringBoolean.FalseString.
Confira também
Aplica-se a
Write(Double)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto do valor de ponto flutuante de precisão dupla especificado no fluxo de saída padrão.
public:
static void Write(double value);
public static void Write (double value);
static member Write : double -> unit
Public Shared Sub Write (value As Double)
Parâmetros
- value
- Double
O valor a ser gravado.
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
A representação de texto de value
é produzida chamando o Double.ToString método .
Confira também
Aplica-se a
Write(Int32)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto do valor inteiro com sinal de 32 bits no fluxo de saída padrão.
public:
static void Write(int value);
public static void Write (int value);
static member Write : int -> unit
Public Shared Sub Write (value As Integer)
Parâmetros
- value
- Int32
O valor a ser gravado.
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
A representação de texto de value
é produzida chamando o Int32.ToString método .
Confira também
Aplica-se a
Write(Int64)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto do valor inteiro com sinal de 64 bits no fluxo de saída padrão.
public:
static void Write(long value);
public static void Write (long value);
static member Write : int64 -> unit
Public Shared Sub Write (value As Long)
Parâmetros
- value
- Int64
O valor a ser gravado.
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
A representação de texto de value
é produzida chamando o Int64.ToString método .
Confira também
Aplica-se a
Write(Decimal)
- Origem:
- Console.cs
- Origem:
- Console.cs
- Origem:
- Console.cs
Grava a representação de texto do valor Decimal especificado, no fluxo de saída padrão.
public:
static void Write(System::Decimal value);
public static void Write (decimal value);
static member Write : decimal -> unit
Public Shared Sub Write (value As Decimal)
Parâmetros
- value
- Decimal
O valor a ser gravado.
Exceções
Ocorreu um erro de E/S.
Exemplos
O exemplo a seguir ilustra o uso do método Write
.
int main()
{
array<String^>^lineInputArr = {"1 2.2 hello TRUE","2 5.22 bye FALSE","3 6.38 see ya' TRUE"};
for ( Int32 i = 0; i < 3; i++ )
{
String^ lineInput = lineInputArr->GetValue( i )->ToString();
String^ aChar = "\t";
array<String^>^fields = lineInput->Split( aChar->ToCharArray() );
Boolean isFirstField = true;
for ( Int32 i = 0; i < fields->Length; 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( fields[ i ] ) ) );
}
catch ( FormatException^ )
{
Console::Write( fields[ i ] );
}
}
Console::WriteLine();
}
}
public class FormatConverter
{
public static void Main(string[] args)
{
string lineInput;
while ((lineInput = Console.ReadLine()) != null)
{
string[] fields = lineInput.Split(new char[] {'\t'});
bool isFirstField = true;
foreach (var item in fields)
{
if (isFirstField)
isFirstField = false;
else
Console.Write(',');
// If the field represents a boolean, replace with a numeric representation.
bool itemBool;
if (Boolean.TryParse(item, out itemBool))
Console.Write(Convert.ToByte(itemBool));
else
Console.Write(item);
}
Console.WriteLine();
}
}
}
let mutable lineInput = Console.ReadLine()
while lineInput <> null do
let fields = lineInput.Split '\t'
let mutable isFirstField = true
for item in fields do
if isFirstField then
isFirstField <- false
else
Console.Write ','
// If the field represents a boolean, replace with a numeric representation.
match Boolean.TryParse item with
| true, itemBool ->
Console.Write(Convert.ToByte itemBool)
| _ ->
Console.Write item
Console.WriteLine()
Public Class FormatConverter
Public Shared Sub Main()
Dim lineInput As String = Console.ReadLine()
While Not lineInput Is Nothing
Dim fields As String() = lineInput.Split(ControlChars.Tab)
Dim isFirstField As Boolean = True
For Each item As String In fields
If isFirstField Then
isFirstField = False
Else
Console.Write(",")
End If
' If the field represents a boolean, replace with a numeric representation.
Dim itemBool As Boolean
If Boolean.TryParse(item, itemBool)
Console.Write(Convert.ToByte(itemBool))
Else
Console.Write(item)
End If
Next
Console.WriteLine()
lineInput = Console.ReadLine()
End While
End Sub
End Class
Comentários
A representação de texto de value
é produzida chamando Decimal.ToString.
Confira também
Aplica-se a
Comentários
https://aka.ms/ContentUserFeedback.
Brevemente: Ao longo de 2024, vamos descontinuar progressivamente o GitHub Issues como mecanismo de feedback para conteúdos e substituí-lo por um novo sistema de feedback. Para obter mais informações, veja:Submeter e ver comentários