Click here to Skip to main content
15,888,323 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello please i am trying to remove some string from a set of string which i loaded from an external file. I am able to loop through all the data in the file with a while loop. After looping through the data i want to remove the first part of the string and add another string to it. For example if this are the data loaded from from the file.
0803456789
0805566788
0802345666
0802334453
0804528721
After looping through i want to remove the first string of each line.Like the first line i will remove the 0 in front and add 234 to it.To give me a new string like 234803456789.I am able to do all that the problem now is that it gives an error saying index and count must refer to a location on the string.Don't know what more to do.Please any help is highly appreciated.Thanks,this is my code so far.
VB
Sub Main()
        Using myreader As StreamReader = New StreamReader("C:\Users\Jamiebones\Desktop\learning_application\learning_application\Phone Number.txt")

            While Not (myreader.EndOfStream)


                Dim line As String = myreader.ReadLine
                Dim jam As String = ""
                jam = "234" & line.Remove(0, 1)


                Console.WriteLine(jam)

            End While
            Console.ReadLine()
            
        End Using


[Edit]Code block added[/Edit]
Posted
Updated 19-Nov-12 7:19am
v4
Comments
Sergey Alexandrovich Kryukov 18-Nov-12 0:15am    
What exactly do you mean by "VB"?
--SA
jamiebones 18-Nov-12 0:17am    
I mean I am coding in visual basic
Sergey Alexandrovich Kryukov 18-Nov-12 0:31am    
I suspect it's VB.NET, is it not?
--SA
Master.Man1980 19-Nov-12 13:58pm    
Why you ask such question o_O. There is no StreamReader in "VB"
Sergey Alexandrovich Kryukov 19-Nov-12 14:11pm    
Why not? Do I look like the one who would even take any interest in VB? :-)
You are the one who is most interested in accurate tagging of the question, to attract people with relevant experience, not me. Got it?
--SA

1 solution

try this

VB
Sub Main()
    Using myreader As StreamReader = New StreamReader("
C:\Users\Jamiebones\Desktop\learning_application\learning_application\Phone Number.txt")

        While Not (myreader.EndOfStream)
            Dim line As String = myreader.ReadLine.Trim 'remove white space
            Dim strBuilder As New Text.StringBuilder 'better for performance
            If String.IsNullOrEmpty(line) = False AndAlso line.Length > 1 Then
                strBuilder.Append("234")
                strBuilder.Append(line.Remove(0, 1))
            End If
            Console.WriteLine(strBuilder.ToString)
        End While
        Console.ReadLine()

    End Using

End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900