StringReader(String) 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化从指定字符串中读取的类的新实例 StringReader 。
public:
StringReader(System::String ^ s);
public StringReader(string s);
new System.IO.StringReader : string -> System.IO.StringReader
Public Sub New (s As String)
参数
- s
- String
应向其初始化的 StringReader 字符串。
例外
参数 s 为 null.
示例
该代码示例是 StringReader 类中的一个较大示例的一部分。
// From textReaderText, create a continuous paragraph
// with two spaces between each sentence.
string aLine, aParagraph = null;
StringReader strReader = new StringReader(textReaderText);
while(true)
{
aLine = strReader.ReadLine();
if(aLine != null)
{
aParagraph = aParagraph + aLine + " ";
}
else
{
aParagraph = aParagraph + "\n";
break;
}
}
Console.WriteLine("Modified text:\n\n{0}", aParagraph);
' 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)
注解
下表列出了其他典型或相关的 I/O 任务的示例。
| 执行此操作... | 请参阅本主题中的示例... |
|---|---|
| 创建文本文件。 | 如何:将文本写入文件 |
| 写入文本文件。 | 如何:将文本写入文件 |
| 从文本文件中读取。 | 如何:从文件读取文本 |
| 将文本追加到文件中。 |
如何:打开日志文件并将其追加到日志文件 File.AppendText FileInfo.AppendText |
| 获取文件的大小。 | FileInfo.Length |
| 获取文件的属性。 | File.GetAttributes |
| 设置文件的属性。 | File.SetAttributes |
| 确定文件是否存在。 | File.Exists |
| 从二进制文件读取。 | 如何:读取和写入新创建的数据文件 |
| 写入二进制文件。 | 如何:读取和写入新创建的数据文件 |