Click here to Skip to main content
11,926,429 members (51,420 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB string
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.
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.
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)

            End While
        End Using

[Edit]Code block added[/Edit]
Posted 17-Nov-12 18:49pm
Edited 19-Nov-12 8:19am
What exactly do you mean by "VB"?
jamiebones 18-Nov-12 0:17am
I mean I am coding in visual basic
I suspect it's VB.NET, is it not?
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?
Master.Man1980 19-Nov-12 14:21pm
I got it, but you don't. Op may tagged it wrongly, but it easy to understand based on his code.
Sergey Alexandrovich Kryukov 19-Nov-12 15:15pm
I know. I do not want to understand anything based on code. Normal people don't want it. Most important, OP does not want it. If the question is poorly tagged, guess who is the looser?
jamiebones 19-Nov-12 19:49pm
please sorry for tagging it wrongly. It was not intentional
Sergey Alexandrovich Kryukov 19-Nov-12 19:59pm
Not a problem, as soon as you tag it finally, but -- wait a minute -- you just said there is not StreamReader in VB. It should mean .NET System.IO.StreamReader, then the tag should be "VB.NET", right?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try this

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(line.Remove(0, 1))
            End If
        End While
    End Using
End Sub

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100