Utf8.sub: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ {{Shared function}} Returns a substring of the string passed. The substring starts at ''i''. If the third argument ''j'' is not given, the substring will end at the...") |
(Restored old example #1 because it shows actual unicode usage instead of handling ASCII text (seriously?), also kept the example #2 from the new version) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 12: | Line 12: | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{OptionalArg}} | {{OptionalArg}} | ||
*'''i:''' | *'''i:''' An integer representing the beginning position (may be negative). | ||
*'''j:''' | *'''j:''' An integer representing the ending position (may be negative). | ||
===Returns=== | ===Returns=== | ||
Returns a ''string'' substring of the original string, containing the selected range. | Returns a ''string'' substring of the original string, containing the selected range from the original string. | ||
==Example== | ==Example== | ||
Line 32: | Line 32: | ||
local output = utf8.sub( input, -4, -1 ) | local output = utf8.sub( input, -4, -1 ) | ||
outputConsole( output ) -- Salı | outputConsole( output ) -- Salı | ||
</syntaxhighlight> | |||
</section> | |||
<section name="Server" class="server" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
local input = "Happy Now" | |||
local output = utf8.sub( input, 1, 5 ) | |||
outputChatBox( output, root, 255,255,255,true ) -- Happy | |||
local output = utf8.sub( input, -3 ) | |||
outputChatBox( output, root, 255,255,255,true ) -- Now | |||
local output = utf8.sub( input, -3, -1 ) | |||
outputChatBox( output, root, 255,255,255,true ) -- Now | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> |
Latest revision as of 10:05, 13 May 2017
Returns a substring of the string passed. The substring starts at i. If the third argument j is not given, the substring will end at the end of the string. If the third argument is given, the substring ends at and includes j.
Syntax
string utf8.sub ( string input [, int i = 1, int j = utf8.len( input ) ] )
Required Arguments
- input: A string character sequence
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.
- i: An integer representing the beginning position (may be negative).
- j: An integer representing the ending position (may be negative).
Returns
Returns a string substring of the original string, containing the selected range from the original string.
Example
Click to collapse [-]
ClientThis example shows how to extract a substring from a UTF-8 string.
local input = "Yarın Salı" local output = utf8.sub( input, 1, 4 ) outputConsole( output ) -- Yarı local output = utf8.sub( input, -4 ) outputConsole( output ) -- Salı local output = utf8.sub( input, -4, -1 ) outputConsole( output ) -- Salı
Click to collapse [-]
Serverlocal input = "Happy Now" local output = utf8.sub( input, 1, 5 ) outputChatBox( output, root, 255,255,255,true ) -- Happy local output = utf8.sub( input, -3 ) outputChatBox( output, root, 255,255,255,true ) -- Now local output = utf8.sub( input, -3, -1 ) outputChatBox( output, root, 255,255,255,true ) -- Now
See Also
- utf8.byte
- utf8.char
- utf8.charpos
- utf8.escape
- utf8.find
- utf8.fold
- utf8.gmatch
- utf8.gsub
- utf8.insert
- utf8.len
- utf8.lower
- utf8.match
- utf8.ncasecmp
- utf8.next
- utf8.remove
- utf8.reverse
- utf8.sub
- utf8.title
- utf8.upper
- utf8.width
- utf8.widthindex