StrInsert$

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > BuiltIn Functions > String functions >

StrInsert$

 

Description

 

Insert a string at a specified position within another string expression.

 

Syntax

 

s$ = STRINSERT$(sMain, sNew, position)

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning

sMain

String

No

Main string to insert to

sNew

String

No

String to insert

Position

Numeric

No

Position inside sMain where to start to insert sNew.

 

Remarks

 

If position is negative it is interpreted as the Token Size. Mainly it will be possible to split MainString into single tokens of the same size inserting the new string.

Example: imagine you have a string and want to insert a comma every 3 bytes. Now you can do it in this way:

Dim MyOldString As String VALUE "123ABC456XYZ"

Dim MyNewString As String VALUE STRINSERT$(MyOldString, ",", -3)

'---MyNewString will be: '123,ABC,456,XYZ,'

 

Restrictions

 

See also

 

String Handling,

 

Examples

 

Thanks to Abraxas for the following script example

Dim sMain      As String VALUE "HELLO WORLD"

Dim sNew       As String VALUE "TO THE "

Dim StringExpression As String VALUE sMain

Dim sDEL       As String

Dim sINS       As String

Dim sREV       As String

Dim sSTR       As String

Dim Start      As DWORD VALUE 4

Dim count      As DWORD VALUE 7

Dim position   As DWORD VALUE 7

Dim sMsg       As String

 

sDEL = STRDELETE$ (StringExpression , start, count)

sINS = STRINSERT$ (sMain, sNew, position)

sREV = STRREVERSE$(sMain)

 

sMsg += "sMain = " & sMain & $CRLF

sMsg += "sNew = " & sNew & $CRLF

sMsg += "StringExpression = " & StringExpression  & $CRLF & $CRLF

sMsg += "Start = " & Start & $CRLF

sMsg += "Count = " & count & $CRLF

sMsg += "Position = " & position & $CRLF & $CRLF

 

sMsg += "STRDELETE$(string_expression, start, count) = " & sDEL & $CRLF & $CRLF

sMsg += "STRINSERT$(sMain, sNew, position) = " & sINS & $CRLF & $CRLF

sMsg += "STRREVERSE$(sMain) = " & sREV & $CRLF & $CRLF

 

MSGBOX 0, sMsg