Utf8.insert: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Shared function}} Inserts a substring into input string. If insert-position is given, the substring will be inserted before the character at this index, otherwise...")
 
m (tweaks)
 
Line 13: Line 13:
===Optional Arguments===
===Optional Arguments===
{{OptionalArg}}
{{OptionalArg}}
*'''insert_pos:''' A number representing the position, where the substring will be inserted at.
*'''insert_pos:''' An integer representing the position, where the substring will be inserted at.


===Returns===
===Returns===

Latest revision as of 18:39, 15 February 2016

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