Utf8.insert

From Multi Theft Auto: Wiki
Revision as of 18:39, 15 February 2016 by Necktrox (talk | contribs) (tweaks)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Inserts a substring into input string. If insert-position is given, the substring will be inserted before the character at this index, otherwise the substring will concatenate to input. The insert position may be negative.

Syntax

string utf8.insert ( string input [, int insert_pos = utf8.len( input ) + 1 ], string substring )

Required Arguments

  • input: A string character sequence
  • substring: A string character sequence which should be inserted

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • insert_pos: An integer representing the position, where the substring will be inserted at.

Returns

Returns a string with the inserted substring value.

Example

Click to collapse [-]
Server

This example shows a command handler for '/insert [something]', which will concatenate the '[something]' after the 'hello ' string in 2 ways.

addCommandHandler("insert", 
    function (player, command, word)
        if word then
            local output = utf8.insert( "hello ", word )
            outputChatBox( output, player )
            
            local output = utf8.insert( "hello ", utf8.len( "hello " ) + 1, word )
            outputChatBox( output, player )
        end
    end
)

See Also