Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2008, 09:52 PM
Registered User
 
Join Date: Nov 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help Needed: StreamWriter Function

Instead of using the AppendText Function, is there a streamwriter function that can be used to replace a line of text inside a textfile?

For example:

The textfile contains the following line:

Monkeys
12

I want to add "1" to the value of 12. If I use the AppendText function then the value of "1" will only be appended next to 12
instead of the value "1" added to 12.

Result:

Monkeys
12
1

instead of getting the result above, i want the to replace the previous value of 12 inside the textfile with the new value of "13". The result that I wanted to see inside the text file is the one below:


Monkeys
13


- where 13 is the new value

What function inside the streamreader and streamwriter class can be used to search and replace text inside a text file


Thank you very much. :)



Once A Newbie Always A Newbie
 
Old August 10th, 2009, 05:50 AM
Authorized User
 
Join Date: Aug 2009
Posts: 18
Thanks: 2
Thanked 0 Times in 0 Posts
Default

This is little bit complex question. First, you need to read the textfile, find string that can be transformed to integer and add number to it. After that, you need to rewrite existing document. I think there is no easy way, because you are mixing strings with integers (of course, all of those characters are chars after all, but only "12" is competetive to add number to it).

Maybe, you can try with function "replace", but it can replace only characters, and it doesn't have logic of adding number to number.
Example:
Dim str1 as New Streamreader
str1.Load("...")
replace(str1,"2", "3")

P.S. I don't know is this going to work, try it!





Similar Threads
Thread Thread Starter Forum Replies Last Post
StreamWriter problem cheh Visual Basic 2008 Essentials 1 August 26th, 2008 03:18 AM
FileStream vs StreamWriter Makolyte C# 2005 0 June 22nd, 2007 01:22 PM
How To Use StreamWriter Slago VS.NET 2002/2003 7 April 4th, 2006 03:32 PM
What object is streamwriter located under? kenn_rosie ASP.NET 1.0 and 1.1 Basics 0 February 21st, 2006 08:10 PM
Month Function needed?? ppenn Access 2 April 1st, 2004 10:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.