TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ValoChele
NA
68
21.6k
How to add numbers to string in a file?
Dec 21 2017 11:16 AM
I have a text file called sample.txt and its contents look like
John Howard Carpenter @#@ born in Carthage, New York,
to mother Milton Jean (Carter) and father Howard Ralph Carpenter.
His family moved to Bowling @#@, Kentucky, @#@ his father, a professor,
was @#@ of the music @#@ at Western Kentucky University.
How do I replace all @#@ by the numbers starting from 1, then incremented by +1 till no @#@ is left in the file.
I've tried
string
x=File.ReadAllText(@
"C:sample.txt"
);
string
y=
"@#@"
;
int
i=1;
MatchCollection matches = Regex.Matches(x, y, RegexOptions.IgnoreCase);
if
(matches.Count>0)
{
foreach
(Match m
in
matches) {
string
n=x.Replace(y,i.ToString());
i++;
File.WriteAllText(y,n);
}
}
MessageBox.Show(
"Done"
);
It does not do anything
BTW: The expected output is
John Howard Carpenter
1
born in Carthage, New York, to mother Milton Jean (Carter) and father Howard Ralph Carpenter. His family moved to Bowling
2
, Kentucky,
3
his father, a professor, was
4
of the music
5
at Western Kentucky University.
Reply
Answers (
4
)
datagridview in window form
creating control on Run time in tablepanellayout