WoW:API strbyte: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
mNo edit summary
m (Move page script moved page API strbyte to API strbyte without leaving a redirect)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
  string.byte(s [, i])
{{luaapi}}
Returns the numerical code of a character in a string.
  indexByte = string.byte(s [, index[, endIndex]])
indexByte = strbyte(s [, index[, endIndex]])


Return the numerical code the i-th character of the string passed.


== Arguments ==
:s [, index[, endIndex]]
:; s : String - The string to get the numerical code from
:; index : Number - Optional argument specifying the index of the character to get the byte value of
:; endIndex : Number - Optional argument specifying the index of the last character to return the value of
== Returns ==
; indexByte : Number - The byte value of the character at the specified position or nil if the index is invalid
== Example ==
  > = string.byte("ABCDE")      -- no index, so the first character
  > = string.byte("ABCDE")      -- no index, so the first character
  65
  65
Line 9: Line 22:
  > = string.byte("ABCDE",0)    -- we're not using C
  > = string.byte("ABCDE",0)    -- we're not using C
  > = string.byte("ABCDE",100)  -- index out of range, no value returned
  > = string.byte("ABCDE",100)  -- index out of range, no value returned
> = string.byte("ABCDE", 1, 3)
65          66          67


[[Category:API Functions|strbyte]]
== Details ==
[[Category:API String Functions|strbyte]]
: The first valid index is 1.
: The last valid index is the length of the string.

Latest revision as of 04:47, 15 August 2023

WoW Lua

Returns the numerical code of a character in a string.

indexByte = string.byte(s [, index[, endIndex]])
indexByte = strbyte(s [, index[, endIndex]])


Arguments[edit]

s [, index[, endIndex]]
s
String - The string to get the numerical code from
index
Number - Optional argument specifying the index of the character to get the byte value of
endIndex
Number - Optional argument specifying the index of the last character to return the value of


Returns[edit]

indexByte
Number - The byte value of the character at the specified position or nil if the index is invalid

Example[edit]

> = string.byte("ABCDE")      -- no index, so the first character
65
> = string.byte("ABCDE",1)    -- indexes start at 1
65
> = string.byte("ABCDE",0)    -- we're not using C
> = string.byte("ABCDE",100)  -- index out of range, no value returned
> = string.byte("ABCDE", 1, 3)
65           66           67

Details[edit]

The first valid index is 1.
The last valid index is the length of the string.