您好我正在尝试填写文本文件中的空行,但只有第69行正在编辑,知道所有行都是空白的,这是我的代码请帮助
Public Sub labelstrings()
Dim lines As String() = File.ReadAllLines(del.filename)
Dim v As Integer
For v = 0 To 69
ReDim lines(v)
If String.IsNullOrWhiteSpace(lines(v)) Then
lines(v) = "ali"
File.WriteAllLines(del.filename, lines)
End If
Next
End Sub
我也试过了:
Public Sub labelstrings()
Dim content As String
content = File.ReadAllText(del.filename)
content = content.Replace(String.IsNullOrWhiteSpace(content), "ali")
File.WriteAllText(del.filename, content)
End Sub
答案 0 :(得分:0)
处理整个数组,然后仅重新编写一次文件。无需重新调暗数组,您应该使用其上限而不是硬编码值:
Public Sub labelstrings()
Dim lines As String() = File.ReadAllLines(del.filename)
For v As Integer = 0 To lines.GetUpperBound(0)
If String.IsNullOrWhiteSpace(lines(v)) Then
lines(v) = "ali"
End If
Next
File.WriteAllLines(del.filename, lines)
End Sub