Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

1 reply to this topic
#1
Posted 14 August 2011 - 12:15 AM
Hello to evreyone i am using Visual Studio 2008 for native program project.
I am using StreamReader and StreamWriter to read and write to file my question is, how can i replace a line with new value without change line.
e.g myfile.txt
blue
red
yellow
and to change to
green
red
yellow
The value is not the same but i want to replace and not to delete and writer new because is organized by ID!
Thank you
I am using StreamReader and StreamWriter to read and write to file my question is, how can i replace a line with new value without change line.
e.g myfile.txt
blue
red
yellow
and to change to
green
red
yellow
The value is not the same but i want to replace and not to delete and writer new because is organized by ID!
Thank you
#2
Posted 18 August 2011 - 09:15 AM
First you need to read the contents of the file line by line. Then if it contains a certain text replace it with your new text.
The above code is obviously not a working example but I hope you get the point.
~ Committed.
ReadFileByLine If Line.Contains("Blue") Line = Line.Replace("Blue", "Green")
The above code is obviously not a working example but I hope you get the point.

~ Committed.
There IS a war going on for your mind.
Nothing of eternal significance happens besides prayer.
Nothing of eternal significance happens besides prayer.
Also tagged with one or more of these keywords: streamwriter, stream
Language Forums →
PHP →
Save JPG image every second - but avoid saving damaged/corrupt images comprised of multiple images?Started by elliottveares, 24 Nov 2015 ![]() |
|
![]() |
||
Language Forums →
C# →
(C#) How to capture video stream without using a third party SDKStarted by BaumHard920, 17 Nov 2014 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
QDataStream: Open QString Values in geditStarted by untitled_1, 16 Feb 2013 ![]() |
|
![]() |
||
General Forums →
General Programming →
Continuous streaming to audio clips.Started by Roman Y, 12 Dec 2012 ![]() |
|
![]() |
||
General Forums →
Everything Else →
Request Services →
Reading Id3 Tags from A SHOUTcast mp3 Radio Stream with PHPStarted by HasanKeyf, 01 Nov 2012 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download