String-Commands * TXT-Command

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > TXT. Text-File Engine > Find- and Replace Operations >

String-Commands * TXT-Command

TXT.Replace_in_Line

Previous Top Next


MiniRobotLanguage (MRL)

 

TXT.ril

TXT.Replace_in_Line
Search a Text in the TXT.-internal Buffer in a specified Line and replace just the first match with a given other string.

 

 

Intention

 

This command is specific in that it will only replace the first match of P2 in the specified Line with P3.

Also you can specify a starting Position in P4.

If you want to replace all occurrences in a Line, you can get the Line-Position using TXT.glp and then use TXT.rep.

Or just call TXT.ril multiple TImes until the TOS returns "0".

The command will leave a "0" or a "1" on the TOS, depending if there was a replace or not.

 

'Replace all "e" with "ef" in internal TXT.-Buffer

VAR.$$LAB=e

VAR.$$LAC=ef

TXT.ril|13|$$LAB|$$LAC|15

ENR.

 

 

 

VAR.$$LAA=?path\..\Pics\Test.txt

TXT.ltf|$$LAA|$$RES

' This example shows all features of TXT.ril

' We are running in 2 times so its clear that due to the Equalcase-Replace,

' also the "EE" will be treated as "ee" and replaced.

TXT.ril|e|EE|520

TXT.ril|e|EE|520

' You can also see that the replace starts a Position 520, as specified.

' So the start of the text is unchanged.

 

 

 

 

Syntax

 

 

TXT.ril|$$LIN|$$SEA|$$REP[|$$STA]

TXT.Replace_in_Line|P1|P2|P3[|P4]

 

 

Parameter Explanation

 

P1 - (Input,numeric) Variable with Line-Number of the Line that shall be searched for something. The first Line is always Line 1.

P2 - (Input) Variable with String to search for.

P3 - (Input) Variable with the String that shall replace the String in P2.

P4 - (optional, numeric) Variable with a Byte-Position in  the TXT.-Buffer, if given the replace will start at that Position.
 If omitted the complete Text is been searched and replaced.

 

TOS: The TXT.ril returns a value of "0" on the TOS if there was no match found.  

         If there was something replaced, a "1" is been returned on the TOS.

 

Example

 

'*****************************************************

' EXAMPLE 1:

'*****************************************************

VAR.$$LAA=?path\..\Pics\Test.txt

TXT.ltf|$$LAA|$$RES

VAN.$$STA=100

'Replace all "e" with "ef" in internal TXT.-Buffer starting from Byte-Position 100

VAR.$$OLD=e

VAR.$$NEW=ef

TXT.ril|13|$$OLD|$$NEW|$$STA

ENR.

 

 

Remarks

 

Will replace only the FIRST occurrences of the Search-String.

 

 

Limitations:

 

-

 

 

See also:

 

 

!TXT. - Text File Engine

TXT.Load Textfile

TXT.Clear

TXT.From_Var

OPT. - Optional Settings

TXT.Replace_in_Text

TXT.Replace

TXT.Replace_in_Line

  Push_Intern

  Pop_Intern  

  Push_Keep

  Pop_Keep

  Clear_Intern

  TXT.Load Textfile

  TXT.Clear  

  TXT.To_Var

  TXT.From_Var

  TXT.To_Var_and_Clear

  TXT.Get_Filename

  TXT.Get_Lenght