简单的问题,我有一个可以多行的文本框(可能不依赖于用户输入),并被称为i:
dim i as string
i = textbox1.text
我需要在每一行的开头插入一个“'”。有可能吗?
之后,将其保存为.txt文件。
祝你好运
答案 0 :(得分:2)
替换所有可能出现的vbCrLf
?
Dim i As String
i = TextBox1.Text
i = "'" + i.Replace(vbCrLf, vbCrLf + "'")
Console.WriteLine(i)
答案 1 :(得分:1)
测试一下:
Dim i As String
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder
With Me.TextBox1 ' .Multiline = True
i = .Text
For y = 0 To .Lines.Count - 1
sb.Append("'")
sb.AppendLine(.Lines(y))
Next
End With
Dim Desktop As String
Dim fileName As String
Dim fileFullPath As String
With My.Computer
Desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
fileName = "TextFile.txt"
fileFullPath = .FileSystem.CombinePath(Desktop, fileName)
Try
.FileSystem.WriteAllText(fileFullPath, sb.ToString, append:=False)
MsgBox(String.Format("File:{0}{0}{1}{2}{0}{0}saved successfully!", vbNewLine, vbTab, fileFullPath))
Shell("notepad.exe " & fileFullPath, AppWinStyle.NormalFocus)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End With
答案 2 :(得分:0)
我认为这就是你要找的东西:
Dim i As String = TextBox1.Text
i = "'" & i.Replace(vbCrLf, vbCrLf + "'")
System.IO.File.WriteAllText("C:\yourtextfile.txt",i)