Visual Basic.NET - MODIFICAR TXT

 
Vista:

MODIFICAR TXT

Publicado por Hèctor Guerrero (10 intervenciones) el 05/10/2007 17:46:32
Buen dìa ,

Haber si alguien me puede apoyar , necesito agregarle en Visual Basic .Net un numero consecutivo a un archivo texto ya generado; si alguien tiene alguna rutina al respecto de antemano gracias por el apoyo

Ejem. del archivo archivo.txt

0001,hector
0001,guerrero
0001,juan

Deseo actualizarlo asì :

0001,hector
0002,guerrero
0003,juan

Gracias de antemano

Hèctor Guerrero
Saludos de Monterrey Mex.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:MODIFICAR TXT

Publicado por kryptic (40 intervenciones) el 05/10/2007 21:13:19
esta podria ser una forma

Dim sr As StreamReader = New StreamReader("C:\d\archivo.txt")
Dim str As String
Dim lineas As String()
Dim i As Integer = 0

str = sr.ReadLine

While Not str = ""
ReDim Preserve lineas(i)
lineas(i) = str
i += 1
str = sr.ReadLine
End While
sr.Close()

Dim sw As StreamWriter = New StreamWriter("C:\d\archivo.txt")

For i = 0 To lineas.Length - 1
lineas(i) = Format(i + 1, "0000") & "," & lineas(i).Substring(lineas(i).IndexOf(CType(",", Char)) + 1)
sw.WriteLine(lineas(i))
Next
sw.Close()

suerte!!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

lo probe

Publicado por German (1 intervención) el 02/06/2009 23:00:48
VOS SABES QUE ESTUVE PROBANDO LO QUE PLANTEASTE:

Dim sr As StreamReader = New StreamReader("C:darchivo.txt")
Dim str As String
Dim lineas As String()
Dim i As Integer = 0

str = sr.ReadLine

While Not str = ""
ReDim Preserve lineas(i)
lineas(i) = str
i += 1
str = sr.ReadLine
End While
sr.Close()

Dim sw As StreamWriter = New StreamWriter("C:darchivo.txt")

For i = 0 To lineas.Length - 1
lineas(i) = Format(i + 1, "0000") & "," & lineas(i).Substring(lineas(i).IndexOf(CType(",", Char)) + 1)
sw.WriteLine(lineas(i))
Next
sw.Close()

PERO NO ME FUNCIONA ME DA ERRORES DE TODOS COLORES...ME PODES DAR UNA RESPUESTA...YO LO QUE NECESITO ES LEER UN ARCHIVO PLANO Y MODIFICAR LOS DATOS QUE TIENE....NECESITO AGRAGARLE UN PAR DE CAMPOS MAS...

MUCHAS GRACIAS KRYPTIC
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

lo probe

Publicado por Dark_zen (9 intervenciones) el 03/06/2011 04:31:23
TE FALTA IMPLEMENTAR

Imports System.IO
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar