generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: #"string" and string.len("string") difference?

Previous Thread :: Next Thread 
noposts is not online. 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 is not online. 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 is not online. noposts
Joined: 16 Jan 2017
Total Posts: 5793
13 Apr 2017 08:33 AM
m ok thnk


Report Abuse
Atavis is not online. 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 is not online. 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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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 is not online. 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
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
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
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
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 is not online. 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
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
13 Apr 2017 09:49 AM
yes actually.
Report Abuse
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
13 Apr 2017 09:49 AM
The number operator can replace string.len
Report Abuse
Nitro509 is not online. 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
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
13 Apr 2017 09:52 AM
@Nitro

Nope
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
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 is not online. Nitro509
Joined: 27 Jun 2010
Total Posts: 11170
13 Apr 2017 09:56 AM
@Goml
Care to elaborate?


Report Abuse
Gomlsauresrex is not online. Gomlsauresrex
Joined: 25 Mar 2016
Total Posts: 3588
13 Apr 2017 09:57 AM
Nvm.

Ignore the post I made about that string.len is not slower
Report Abuse
ChiefDays is not online. 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 is not online. 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
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
13 Apr 2017 10:00 AM
ok i forgot one step in making string.len slower


Capitalist atheist
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image