Note that there are some explanatory texts on larger screens.

plurals
  1. POFind and replace file lines
    primarykey
    data
    text
    <p>I have a text file with over 12,000 lines. In that file I need to replace certain lines. Some lines begin with a <code>;</code>, some have random words, some start with space. However, I am only concerned with the two types of lines I describe below. </p> <p>I have a line like </p> <pre><code> SET avariable:0 ;Comments </code></pre> <p>and I need to replace it to look like </p> <pre><code> set aDIFFvariable:0 :Integer // comments </code></pre> <p>The only CASE that is necessary is in the word <code>Integer</code> <code>I</code> needs to be capitalized.</p> <p>I also have </p> <pre><code> String aSTRING(7) ;Comment </code></pre> <p>that needs to look like</p> <pre><code> STRING aSTRING(7) :array [0..7] of AnsiChar; // Comments </code></pre> <p>I need to keep all the spacing the same. </p> <p><strong>Here is what I have so far</strong></p> <pre><code>static void Main(string[] args) { string text = File.ReadAllText("C:\\old.txt"); text = text.Replace("old text", "new text"); File.WriteAllText("C:\\new.txt", text); } </code></pre> <p>I think I need to use REGEX, which I have tried to make for my first example: </p> <p><code>\s\s[set]\s*{4}.*[:0]\s*[;].*</code> &lt;-- I now know this is invalid - please advise</p> <p>I need help with properly setting up my program to find and replace those lines. Should I read one line at a time and if it matches then do something? I am confused really as to where to start. </p> <p>BRIEF pseudo code of what I want to do</p> <pre><code>//open file //step through file //if line == [regex] then add/replace as needed //else, go to next line //if EOF, close file </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload