From Multi Theft Auto: Wiki
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.


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 a string with the inserted substring value.


Click to collapse [-]

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

    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 )

See Also