Hitachi

JP1 Version 11 JP1/Script Description and Reference (For Windows Systems)


8.5.3 TextFileReplace (replace a string in a text file)

Purpose

Replaces a specified string in a text file.

Syntax
TextFileReplace (FileName, OldText, NewText [, ReplaceCntBuff])
Arguments
FileName

Specify a text file name as a character string or as a variable that stores this value.

If you omit the extension, .TXT is automatically appended to the file name. However, in JP1/Script 06-00 and later versions, if you specify a file name ending with the extension period (.), the file is regarded as having no extension.

OldText

Write the string to be replaced, or specify a variable that stores this value.

NewText

Write the new string, or specify a variable that stores this value.

ReplaceCntBuff (from version 06-00)

Specify a variable for storing the number of strings replaced by the command. Omit this argument if not required.

Description

The TextFileReplace command searches for the specified string in the text file and replaces it with the new string. The command returns True on successful execution, or False if an error occurs.

This command does not support large files. If necessary, use the command from SplitFile (split a file).

Note

Take care when specifying a file in the folder set in the environment variable ProgramFiles (normally the Program Files folder on the system drive) or WinDir (normally the Windows folder on the system drive). For details, see 1.8.2 Command behavior.

Important note

The command does not convert a linefeed code in the file to the new character string even if the linefeed code is specified as the old character string.

Example
The script below executes the TextFileReplace command on the file ABC.TXT.
TextFileReplace ( _BIN_+"ABC.TXT" ,"TEST" ,"test" )
[Contents of the ABC.TXT file before execution]
**********
**TEST**
**********
[Contents of the ABC.TXT file after execution]
**********
**test**
**********
JP1/Script version

Supported from JP1/Script 01-00.