user3283415
user3283415

Reputation: 119

C# separate the words in a text file

I have a text file with many words separated by ;. It looks like this:

eye;hand;mouth;arms;book
three;head;legs;home

I would like to go through this file and search for the symbol ; and modify the file so that every word is transposed with line break.

Should I read the text file in a string first with,

string path = @"c:\temp\MyTest.txt";
string readText = File.ReadAllText(path);

Then check:

if readText.contains(";");

But I don't know what to do next

Upvotes: 2

Views: 818

Answers (3)

Jacek Cz
Jacek Cz

Reputation: 1906

Did you mean this?

string g = readText.Replace(";", "\n");

Upvotes: 1

rashfmnb
rashfmnb

Reputation: 10538

use

readText.Replace(";",Environment.NewLine) 

Upvotes: 2

Dzianis Yafimau
Dzianis Yafimau

Reputation: 2016

string readText = File.ReadAllText(path);
var result = readText.Replace(";", Environment.NewLine);

Upvotes: 6

Related Questions