Home All Groups Group Topic Archive Search About

[VB2008] How to replace lines in a textfile?

Author
27 Nov 2007 9:23 AM
Maurice van 't Loo
Hi,

I'm pretty new with VB, especialy with 2008 Express :-p So i need your
help...

I have a text file containing:

    VERSION 3
    ADDEDVERSION 5
    OPTION_GUILD_RECRUITMENT_CHANNEL AUTO
    CHANNELS
    guild 1 3
    dutchworld 1 4
    WorldTrade 1 5
    GMhelp 1 6
    END
    ZONECHANNELS 16777216
    COLORS
    SAY 255 255 255
    ....
    ....

And i want to replace the part between CHANNELS and END
I allready found a way to read those lines and change it in the way i want
and put it in an array ( Dim channel_names(0 To 10) As String )

Now i want to replace those 4 lines with my array.

Does anyone has an idea to do this?
Or can anyone give me some hints or examples?

Thanks,
Maurice

Author
27 Nov 2007 9:33 AM
Armin Zingler
Show quote Hide quote
"Maurice van 't Loo" <nospam@nospam.nl> schrieb
> Hi,
>
> I'm pretty new with VB, especialy with 2008 Express :-p So i need
> your help...
>
> I have a text file containing:
>
>    VERSION 3
>    ADDEDVERSION 5
>    OPTION_GUILD_RECRUITMENT_CHANNEL AUTO
>    CHANNELS
>    guild 1 3
>    dutchworld 1 4
>    WorldTrade 1 5
>    GMhelp 1 6
>    END
>    ZONECHANNELS 16777216
>    COLORS
>    SAY 255 255 255
>    ....
>    ....
>
> And i want to replace the part between CHANNELS and END
> I allready found a way to read those lines and change it in the way
> i want and put it in an array ( Dim channel_names(0 To 10) As String
> )
>
> Now i want to replace those 4 lines with my array.
>
> Does anyone has an idea to do this?
> Or can anyone give me some hints or examples?

Put 'em in a List(Of String) and you can remove and add items using the Add,
AddRange and RemoveAt methods.


Armin
Author
28 Nov 2007 3:03 PM
Alekszander Moses, Antifa-Rat Zureich
Show quote Hide quote
On 27 Nov., 10:33, "Armin Zingler" <az.nos***@freenet.de> wrote:
> "Maurice van 't Loo" <nos...@nospam.nl> schrieb
>
>
>
>
>
> > Hi,
>
> > I'm pretty new with VB, especialy with 2008 Express :-p So i need
> > your help...
>
> > I have a text file containing:
>
> >    VERSION 3
> >    ADDEDVERSION 5
> >    OPTION_GUILD_RECRUITMENT_CHANNEL AUTO
> >    CHANNELS
> >    guild 1 3
> >    dutchworld 1 4
> >    WorldTrade 1 5
> >    GMhelp 1 6
> >    END
> >    ZONECHANNELS 16777216
> >    COLORS
> >    SAY 255 255 255
> >    ....
> >    ....
>
> > And i want to replace the part between CHANNELS and END
> > I allready found a way to read those lines and change it in the way
> > i want and put it in an array ( Dim channel_names(0 To 10) As String
> > )
>
> > Now i want to replace those 4 lines with my array.
>
> > Does anyone has an idea to do this?
> > Or can anyone give me some hints or examples?
>
> Put 'em in a List(Of String) and you can remove and add items using the Add,
> AddRange and RemoveAt methods.

Hi Armin,

a StringCollection could do the same, oder?

We don't need generic class when a specialiced class already
exists. ;-)

Gruss an Herrn Zingler
Author
28 Nov 2007 3:15 PM
Armin Zingler
Show quote Hide quote
"Alekszander Moses, Antifa-Rat Zureich" <ejpd.***@gmail.com> schrieb
> On 27 Nov., 10:33, "Armin Zingler" <az.nos***@freenet.de> wrote:
> > "Maurice van 't Loo" <nos...@nospam.nl> schrieb
> >
> >
> >
> >
> >
> > > Hi,
> >
> > > I'm pretty new with VB, especialy with 2008 Express :-p So i
> > > need your help...
> >
> > > I have a text file containing:
> >
> > >    VERSION 3
> > >    ADDEDVERSION 5
> > >    OPTION_GUILD_RECRUITMENT_CHANNEL AUTO
> > >    CHANNELS
> > >    guild 1 3
> > >    dutchworld 1 4
> > >    WorldTrade 1 5
> > >    GMhelp 1 6
> > >    END
> > >    ZONECHANNELS 16777216
> > >    COLORS
> > >    SAY 255 255 255
> > >    ....
> > >    ....
> >
> > > And i want to replace the part between CHANNELS and END
> > > I allready found a way to read those lines and change it in the
> > > way i want and put it in an array ( Dim channel_names(0 To 10)
> > > As String )
> >
> > > Now i want to replace those 4 lines with my array.
> >
> > > Does anyone has an idea to do this?
> > > Or can anyone give me some hints or examples?
> >
> > Put 'em in a List(Of String) and you can remove and add items
> > using the Add, AddRange and RemoveAt methods.
>
> Hi Armin,
>
> a StringCollection could do the same, oder?
>
> We don't need generic class when a specialiced class already
> exists. ;-)


Thx. There are so many possibilites nowadays that not all of them come to my
mind immediatelly. :-)

Though, a StringCollection is internally implemented as an Arraylist, so
type casting has to be done each time an Item is returned. That's why I'd
prefer the List(Of String).


Armin