Need assistance to do this. Or advice about how to add string to string elements in array?
-
We have 2 txt files with 100 or more strings in each:
domain.txt
domain1
domain2
..
title.txt
title1
tilte2
.. -
and we have:
string link = < a h ref=”http://www.domain.com” target=”_blank”>title< /a>
-
After reading files we would have 2 string arrays – we need to replace domain.com with each string from domain.txt and title with each string from title.txt like this:
< a h ref=”http://www.domain1.com” target=”_blank”>title1< /a>
< a h ref=”http://www.domain2.com” target=”_blank”>title2< /a>
.. -
Save the result string array into 2 txt files in that way: from 1-50 strings to
1.txt and from 50-100 to 2.txt file
What is the best way to do this by manipulating strings with strings array elements?
This is probably the simplest way to read the files:
To make the substitutions you can use
string.Format:To write the output you can use Linq:
If your template is a paramter you might want to construct the format string dynamically rather than hardcoding it. Here is an example of how you could do that: