Borrar coma al final de cadena
Hola, estoy en un proyecto que debe exportar un datagrid a txt, hasta ahí bien, pero debo borrar la última coma, he intentado trimend, remove sin resultados satisfactorios.
MI código es:
Private Sub btntxt57_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntxt57.Click
Const RUTA As String = "C:\Documents and Settings\Administrador\Mis documentos\Visual Studio 2005\Projects\consoft\consoft\bin\Debug\data.txt"
Dim strExport As String = ""
For Each dr As DataGridViewRow In dgv57.Rows
For Each dl As DataGridViewColumn In dgv57.Columns
If dr.Cells(dl.Name).Value IsNot Nothing And dl.HeaderText <> "Detalle" Then
strExport += dr.Cells(dl.Name).Value.ToString() + ","
End If
Next
strExport += Environment.NewLine.ToString()
Next
strExport = strExport.Substring(0, strExport.Length - 3) + Environment.NewLine.ToString()
'Create a TextWrite object to writ7e to file, select a file name with .csv extention
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter("data.txt")
'Write the Text to file
tw.Write(strExport)
'Close the Textwrite
tw.Close()
Process.Start(RUTA)
End Sub
Agradezco de antemano su atención.
MI código es:
Private Sub btntxt57_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntxt57.Click
Const RUTA As String = "C:\Documents and Settings\Administrador\Mis documentos\Visual Studio 2005\Projects\consoft\consoft\bin\Debug\data.txt"
Dim strExport As String = ""
For Each dr As DataGridViewRow In dgv57.Rows
For Each dl As DataGridViewColumn In dgv57.Columns
If dr.Cells(dl.Name).Value IsNot Nothing And dl.HeaderText <> "Detalle" Then
strExport += dr.Cells(dl.Name).Value.ToString() + ","
End If
Next
strExport += Environment.NewLine.ToString()
Next
strExport = strExport.Substring(0, strExport.Length - 3) + Environment.NewLine.ToString()
'Create a TextWrite object to writ7e to file, select a file name with .csv extention
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter("data.txt")
'Write the Text to file
tw.Write(strExport)
'Close the Textwrite
tw.Close()
Process.Start(RUTA)
End Sub
Agradezco de antemano su atención.
1 respuesta
Respuesta de Luis Angel Octavio Alcaraz Barajas
1