String Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > String commands > !STR.- String Command > BASIC-String Commands >

String Operations

STR.SetMidCountB / STR.SmiB

Previous Top Next


MiniRobotLanguage (MRL)

 

STR.SetMidCountB

Replace a Substring with a Specified Count of Characters using a traditional BASIC Algo which will keep the String length

 

clip1149

 

 

Intention

 

This command is used to replace a substring within a main string, starting from a specified position and for a specified count of characters.

The final string will be written back to the variable in P1. This command performs an overwrite operation and can NOT change the length of the string in P1.

 

 

 

Syntax

 

 

STR.SetMidCountB|P1|P2|P3|P4

STR.SmiB|P1|P2|P3|P4

 

 

 

Parameter Explanation

 

P1 - Main string variable where the replacement will occur.

P2 - Start position in the main string. If negative, the position is counted backwards from the end of the string (-1 is the last character).

P3 - Count of characters to replace from the start position. If omitted, all characters from the start position to the end of the string are replaced.

P4 - Replacement string. If the replacement string is longer than the count specified, it will be truncated. If it is shorter, it will replace characters one-for-one and the remaining characters in the target area will be unchanged.

 

 

 

Example

 

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

' STR.-Sample

'***********************************
$$ SRC=

 $$STA=7

$$ CNT=5

 $$REP=Universe

STR.SetMidCountB|$$ SRC| $$STA|$$ CNT| $$REP

' $$SRC will now contain "" because the length cannot change.

ENR.

 

 

 

 

Remarks

 

  This command uses the behavior of the BASIC MID$ statement.

  The length of the string in P1 will never be changed by this command. If the replacement string in P4 is longer than the specified count (P3), the replacement string will be truncated to fit.

  If the start position (P2) is zero or outside the bounds of the string, no operation is performed.

 

 

See also:

 

  STR.SetMidCount

  STR.SetMidTo

  STR.SetMidToB