Ver Mensaje Individual
  #41 (permalink)  
Antiguo 07/08/2008, 03:59
Avellaneda
Colaborador
 
Fecha de Ingreso: enero-2008
Ubicación: Unas veces aquí, otras veces allí
Mensajes: 1.482
Antigüedad: 17 años, 3 meses
Puntos: 37
Respuesta: Visual Basic 2005: Grabar y leer .ini

Cita:
Iniciado por moradazo Ver Mensaje
Cómo puedo hacer una condición que me diga si una línea empieza por "[", que ponga al final de la cadena un "]"

Tengo este código:

Código:
If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
            Do While objReader.Peek() <> -1
             If objReader.ReadLine.StartsWith("[") Then
                   TextLine = objreader.readline & "]" & vbNewLine
             Else
                   TextLine = TextLine & objreader.readline & vbNewLine
             End If
            Loop
            TextBox1.Text = TextLine
Al ver el Textbox, me sale todo malo, pone "]" por todos lados, si alguien me puede decir en donde estoy equivocado. Gracias
A ver, prueba así:

Código:
If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
            Dim sLinea As String = ""
            Dim TextLine As String = ""
            Do While objReader.Peek() <> -1
                sLinea = objReader.ReadLine()
                If sLinea.StartsWith("[") Then sLinea = sLinea & "]"
                TextLine = TextLine & sLinea & vbNewLine
            Loop
            TextBox1.Text = TextLine
Amigo moradazo, una pequeña observación:
Procura no alargar tanto el mismo tema, pues se hace muy pesado además de que las últimas preguntas no tienen nada que ver con el título original.

un saludo