Please enable JavaScript to view this site.

thinBasic Help Manual

* * HELP & MANUAL PREMIUM PACK 4 DEMO VERSION * *

This documentation was styled with a demo skin from the Premium Pack 4 add-on for Help & Manual. The contents of the skin are encrypted and not configurable. You can only publish HM projects with this skin. You cannot edit it or change it.

This version is copyright and may only be used for local testing purposes. It may not be distributed.

Please purchase the full version of the Premium Pack to get the configurable skins and remove this notice. The package will also include the Toolbox configuration utility for Premium Pack skins.

 

Description

 

Within a specified string, replace all occurrences of one string with another string.

 

Syntax

 

s = REPLACE$(sMainString, [ANY] sMatchString, [WITH] sNewString)

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning









 

Remarks

 

If you use the ANY option without using WITH option ...

each occurrence of each character in sMatchString will be replaced with the corresponding character in sNewString.

In this case, sMatchString and sNewString must be the same length, because there is a one-to-one correspondence between their characters.

If sMatchString and sNewString will differ in size, no substitution will take place and sMainString string will be returned

 

If you use the ANY option in conjunction with WITH option

each occurrence of each character in sMatchString will be replaced with sNewString within sMainString.

 

Restrictions

 

See also

 

String Handling,

 

Examples

 

Thanks to Abraxas for the following script example

 

Dim sMainString        As String VALUE "HELLO WORLD"

Dim sMatchString       As String VALUE "LO"

Dim sStringExpression  As String VALUE "ThinBasic "

Dim sNewString         As String VALUE "R"

Dim sREP   As String

Dim sREM   As String

Dim sRPL   As String

Dim Count  As DWORD VALUE 10

Dim sMsg   As String

 

sREP = REPEAT$(Count, sStringExpression)

sREM = REMOVE$(sMainString,sMatchString)

sRPL = REPLACE$(sMainString, Any sMatchString, With sNewString)

 

sMsg += "sMainString = " & sMainString & $CRLF

sMsg += "sMatchString = " & sMatchString & $CRLF

sMsg += "sStringExpression = " & sStringExpression & $CRLF

sMSG += "Count = " & Count & $CRLF & $CRLF

sMsg += "REPEAT$(Count, StringExpression) = " & sREP & $CRLF & $CRLF

sMsg += "REMOVE$(sMainString,sMatchString) = " & sREM & $CRLF & $CRLF

sMsg += "REPLACE$(sMainString, [ANY] sMatchString, [WITH] sNewString) = " & sRPL & $CRLF & $CRLF

 

MSGBOX 0, sMsg

 

 

 

 

Created with Help+Manual 8 and styled with Premium Pack Version 4 © by EC Software