© Matti Mattila, CPFA, CISA, CIA

TexEdiMac: Replace Character(s)

Previous item Next item Previous menu
Test Design
Picture 1
Picture 2
Picture 6
Picture 7
- In picture 1 a file (source file) is shown that will be used in demonstrating 'Replace Character(s)'-functionality of 'TexEdiMac' (later renamed as 'TexEdi') macro.
- The objective is to perform the following tasks:
(1) replace spaces with "0"s and "," with "." in positions 18-31;
(2) replace string "98" with "1998" in positions 5-6; and
(3) replace spaces with nothing in positions 18-23.
Running the macro, task #1
- The easiest way to run the macro is pressing simultaneously Ctrl + Shift + 't'.
- The macro shows the form in picture 2. Select 'Replace Character(s)' on it.
- The macro informs briefly what it does (picture 3). Read the information, and click 'Yes' [= 'Kyllä' in picture 3] in order to proceed.
Picture 3
- Macro will ask to select a text file file where to replace characters (picture 4). Please, click 'Yes', and browse to find the source file.
Picture 4
Picture 5
- In picture 5 'test.txt' in folder 'RepCha' will be selected [as source file].
- In its next message the macro suggests a name to the new file: the body of the name of the source file, with a bit different extension ('tx9 in stead on 'txt' in the example).
On the form (picture 5), where the file name was suggested, you can change the extension of the [resulting] new file, if you do not want it to be 'tx9'. You do not need to write anything in the box 'File extension is stead of 'tx9'' when you decide to use extension 'tx9' [2].
- The macro tells the path and name of the resulting file (not shown in pictures; it will be: 'D:/RepCha/test.tx9').
- The macro tells count of lines, and lenghts of the shortedt and the longest lines in source file [not shown in pictures]. Read the informationand proceed.
- When preceeding you are shown a form where to make replacement choices. In picture 7 we make the macro replace ('What to replace:') spaces [not visible] and commas ('with What:') with zeros and periods in positions 18 to 31, the mentioned positions included. Each space will be replaced with '0', and each ',' wil be replaced with '.' 'Replace Characters as a String' remains unchecked because we want to replace both characters separately - not as one string.
The macro replaces first 'What to replace' character with first 'with What' character, second 'What to replace' character with second 'with What' character, etc. If there would be 'What to replace' character with no corresponding 'with What' 'What to replace' character would be replaced with nothing, i.e. just removed.
- The macro informs about the count of replacement (53) [not shown in pictures here].
The new text file that resulted from the run is shown in picture 8.
We can see that the replacement was succesful.
Picture 8
Running the macro, task #2
Picture 9
- Objective of the second task is replacement of string "98" with "1998" in positions 5-6 of the cource file.
- Running of the macro consists of same steps as in the first run until to the step, where one selects what to replace with what (picture 7).
- We fill in 'Replace What with What' form as shown in picture 9. It is important to check 'Replace Characters as a String'. Leaving it unchecked would make the macro to replace '9' and '8' with '1' and '9' respectively.
- The new text file that resulted from the run is shown in picture 10.
We can see that string '98' has succesfully been replaced with longer string '1998'.
Picture 10
Running the macro, task #3
Picture 11
- Objective of the last task is to replace spaces with nothing in positions 18-23 of the source file. Such a replacement means removal of text in the aforementioned positions.
- Running of the macro consists of same steps as in the first run until to the step, where one selects what to replace with what (picture 7).
- We fill in 'Replace What with What' form as shown in picture 10. Both 'What to repace' and 'with What' are left empty.
- The new text file that resulted from the run is shown in picture 12.
We can see that in the new file there are six spaces less in the middle part of the lines compared with the lines of the source file.
Picture 12

[1] Text (to the left) on "Guidance" worksheet of "TexEdiMac.xls": what the macro does.
[2] The macro does not use special characters in an extension.