REPLACE()

REPLACE(S1,S2,N,P)

REPLACES THE STRING S1 BY S2 IN THE SYSTEM OBJECT NUMBER N, FROM THE POSITION P, AND RETURNS THE POSITION OF THE LAST CHARACTER OF THE REPLACED STRING

  • Type: Function
  • Parameters: 4
  • Group: Strings

ACTION

The function REPLACE((S1$,S2$,N,P) replaces the string S1$ by S2$ in the source of system object number N, from the position P, selects the string S2$ and returns the position of the last character of the replaced string, or -1 if string S1$ is not found.

So, it is easy to replace all the occurences of a string by another string in a source, by calling the function REPLACE with the position P from a previous call.

The system object is of type : MEMO, MEMO_RICH, SYNEDIT.

SYNTAX: Result=REPLACE(S1,S2,N,P)

  • S1 = string expression.
  • S2 = string expression.
  • N = real or integer expression.
  • P = real or integer expression.

USE

  • The function FIND() is used to replace a string ky another in an object.

ERROR

  • If number N is not a correct expression.
  • If number N exceeds the allowed maximum number of system objects.
  • If number N is less than 0.
  • If the system object number N does not exist.
  • If the object number N is not of type : MEMO, MEMO_RICH, SYNEDIT.
  • If S1 is not a correct string expression.
  • If S2 is not a correct string expression.
  • If P is not a correct arithmetic expression.

EXAMPLE

rem create a SYNEDIT

dim pos

synedit 1:height 1,280

item_add 1,"dim a"

item_add 1,"a=12345"

wait 1000

rem replace 2345 by 11 and return position of last character

pos=replace("2345","11",1,pos)

caption 0,"position of last character="+str$(pos)

SEE ALSO

MEMO

MEMO_RICH

SYNEDIT

FIND()