本文整理汇总了VB.NET中System.IO.StringWriter类的典型用法代码示例。如果您正苦于以下问题:VB.NET StringWriter类的具体用法?VB.NET StringWriter怎么用?VB.NET StringWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringWriter类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: StrReader
Option Explicit
Option Strict
Imports System.IO
Public Class StrReader
Shared Sub Main()
Dim textReaderText As String = "TextReader is the " & _
"abstract base class of StreamReader and " & _
"StringReader, which read characters from streams " & _
"and strings, respectively." & _
vbCrLf & vbCrLf & _
"Create an instance of TextReader to open a text " & _
"file for reading a specified range of characters, " & _
"or to create a reader based on an existing stream." & _
vbCrLf & vbCrLf & _
"You can also use an instance of TextReader to read " & _
"text from a custom backing store using the same " & _
"APIs you would use for a string or a stream." & _
vbCrLf & vbCrLf
Console.WriteLine("Original text:" & vbCrLf & vbCrLf & _
textReaderText)
' From textReaderText, create a continuous paragraph
' with two spaces between each sentence.
Dim aLine, aParagraph As String
Dim strReader As New StringReader(textReaderText)
While True
aLine = strReader.ReadLine()
If aLine Is Nothing Then
aParagraph = aParagraph & vbCrLf
Exit While
Else
aParagraph = aParagraph & aLine & " "
End If
End While
Console.WriteLine("Modified text:" & vbCrLf & vbCrLf & _
aParagraph)
' Re-create textReaderText from aParagraph.
Dim intCharacter As Integer
Dim convertedCharacter As Char
Dim strWriter As New StringWriter()
strReader = New StringReader(aParagraph)
While True
intCharacter = strReader.Read()
' Check for the end of the string
' before converting to a character.
If intCharacter = -1 Then
Exit While
End If
convertedCharacter = Convert.ToChar(intCharacter)
If convertedCharacter = "."C Then
strWriter.Write("." & vbCrLf & vbCrLf)
' Bypass the spaces between sentences.
strReader.Read()
strReader.Read()
Else
strWriter.Write(convertedCharacter)
End If
End While
Console.WriteLine(vbCrLf & "Original text:" & vbCrLf & _
vbCrLf & strWriter.ToString())
End Sub
End Class