2014-11-02 53 views
-1

簡單的問題,我有可multilined(它可能沒有被根據用戶輸入),如i被稱爲一個文本框:多行文本框開始,每行一個特殊字符

dim i as string 
i = textbox1.text 

我需要在每一行的開頭插入「'」是否可能?

之後,將其保存到.txt文件。

問候

+0

@MikkoViitala你能不能舉個例子? – 2014-11-02 19:12:23

+3

堆棧溢出不是代碼寫入服務... – Psychemaster 2014-11-02 19:16:14

回答

2

更換的vbCrLf也許所有出現?

Dim i As String 
i = TextBox1.Text 

i = "'" + i.Replace(vbCrLf, vbCrLf + "'") 
Console.WriteLine(i) 
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 
0

我認爲這是你在找什麼:

Dim i As String = TextBox1.Text 
i = "'" & i.Replace(vbCrLf, vbCrLf + "'") 
System.IO.File.WriteAllText("C:\yourtextfile.txt",i) 
相關問題