noposts
|
  |
| Joined: 16 Jan 2017 |
| Total Posts: 5793 |
|
|
| 13 Apr 2017 08:19 AM |
the # thing returns the number of characters in the string you put, exactly like string.len(). string.len("string") returns 6 just like #"string" does.
any difference for them?
|
|
|
| Report Abuse |
|
|
Atavis
|
  |
| Joined: 10 Apr 2012 |
| Total Posts: 1463 |
|
|
| 13 Apr 2017 08:23 AM |
I think there is but it's probably negligible This is alike to table.getn(t) and #t
#code --This validates my comment. |
|
|
| Report Abuse |
|
|
noposts
|
  |
| Joined: 16 Jan 2017 |
| Total Posts: 5793 |
|
| |
|
Atavis
|
  |
| Joined: 10 Apr 2012 |
| Total Posts: 1463 |
|
|
| 13 Apr 2017 08:38 AM |
ah just read ... "Some functions in the string library are quite simple: string.len(s) returns the length of a string" from chapter 20 of Programming in Lua
"The length operator [#] works on strings and tables. On strings, it gives the number of bytes in the string. On tables, it gives the length of the sequence represnted by the table."
I'm still reading into the difference between string bytes and the length of the string as an array/sequence.
#code --This validates my comment. |
|
|
| Report Abuse |
|
|
Atavis
|
  |
| Joined: 10 Apr 2012 |
| Total Posts: 1463 |
|
|
| 13 Apr 2017 08:39 AM |
second quote from chapter 3.5 of Programming in Lua
#code --This validates my comment. |
|
|
| Report Abuse |
|
|
Atavis
|
  |
| Joined: 10 Apr 2012 |
| Total Posts: 1463 |
|
|
| 13 Apr 2017 08:40 AM |
omk, lua strings are eight-bit.
Basically the same thing.
Not sure what the exact difference is.
#code --This validates my comment. |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2017 09:02 AM |
"On strings, it gives the number of bytes in the string." So the length of the string, lol. Perhaps Lua can be modified for UTF-16 and other formats.
|
|
|
| Report Abuse |
|
|
Nitro509
|
  |
| Joined: 27 Jun 2010 |
| Total Posts: 11170 |
|
|
| 13 Apr 2017 09:35 AM |
Strings are 8-bit? What do you mean? That is uses the standard ASCII code?
|
|
|
| Report Abuse |
|
|
Atavis
|
  |
| Joined: 10 Apr 2012 |
| Total Posts: 1463 |
|
|
| 13 Apr 2017 09:36 AM |
Ye it can @Jarod
#code --This validates my comment. |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2017 09:41 AM |
"#" is the number operator, which will return the number of items in something.
For example : local tbl={1, 2, 3} print(#tbl) -- > 3
string.len returns the number of characters in a given string.
For example : local msg="Hello World" print(string.len(msg)) -->11 |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2017 09:47 AM |
| Well the difference is that "#" can be used to get the number of characters in a string and the number of items in something while string.len is only used for getting the number of characters in a given string. |
|
|
| Report Abuse |
|
|
Atavis
|
  |
| Joined: 10 Apr 2012 |
| Total Posts: 1463 |
|
|
| 13 Apr 2017 09:48 AM |
So in the context of ROBLOX string.len() is pretty "useless", in comparison to #?
#code --This validates my comment. |
|
|
| Report Abuse |
|
|
| |
|
|
| 13 Apr 2017 09:49 AM |
| The number operator can replace string.len |
|
|
| Report Abuse |
|
|
Nitro509
|
  |
| Joined: 27 Jun 2010 |
| Total Posts: 11170 |
|
|
| 13 Apr 2017 09:51 AM |
string.len is probably slower since it has to call a library high in the stack. # is faster.
|
|
|
| Report Abuse |
|
|
| |
|
|
| 13 Apr 2017 09:55 AM |
im pretty sure string.len is slower since you have to index the string table, then call a function
Capitalist atheist |
|
|
| Report Abuse |
|
|
Nitro509
|
  |
| Joined: 27 Jun 2010 |
| Total Posts: 11170 |
|
| |
|
|
| 13 Apr 2017 09:57 AM |
Nvm.
Ignore the post I made about that string.len is not slower |
|
|
| Report Abuse |
|
|
ChiefDays
|
  |
| Joined: 26 Sep 2016 |
| Total Posts: 502 |
|
|
| 13 Apr 2017 09:59 AM |
#string is faster than string.len(string).
local t t = tick() print(#"AA", math.floor((tick()-t))*10^10) t = tick() print(string.len("AA"), math.floor((tick()-t)*10^10))
Results: First message delay is always lower than the second.
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 13 Apr 2017 09:59 AM |
string.len is slower. Not functionally but for the reason that it takes time to fetch a global and read from a table and call a C function.
String.len is a thing because the '#' operator didn't do that in older versions of Lua |
|
|
| Report Abuse |
|
|
|
| 13 Apr 2017 10:00 AM |
ok i forgot one step in making string.len slower
Capitalist atheist |
|
|
| Report Abuse |
|
|