Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

String Manipulations? "String." Question

Asked by 9 years ago

I'm a bit confused with String.(WhateverHere). What i'm confused of is the String part. I'm asking about:

string.len() --The string part
string.lower() -- The string part, Function doesn't matter, I'm showing it doesn't matter by showing two different functions

I've noticed I can do something like this:

plr.Chatted:connect(function(msg)
    if string.lower(string.sub(msg,1,5)) == "load " then
    end
end)

and the script knows that the string is the message. Yet if I were to do something like this in a script:

for _,Map in pairs(MapTable) do
    if string.match(string.lower(string.sub(msg,6))) == string.lower(Map.Name) then
    end
end

I'll be thrown an error because the script doesn't know the string it's looking for?

  • Can I be given an explanation on what it's doing?

  • Can't string be switched out with, well, a string?

1 answer

Log in to vote
0
Answered by
Unclear 1776 Moderation Voter
9 years ago

stringis a variable that implicitly refers to the built-in string library. You can check out the contents of the string library here.

Because it is a library, it is basically a table full of useful functions you can use to do things with strings. That is why you first refer to string, and then the name of a function you want to use from the string library.

However, do know that nearly all of the string functions are also available as methods you can use on strings. For example, you can do this:

local word          = "ABC"
local firstWay      = string.lower(word)
local secondWay     = word:lower()
print(firstWay == secondWay) --> true

Note: The reason why your code with match errored is because match requires two arguments. You only gave one. Read more about match here.

0
Oh, match is a tuple. alphawolvess 1784 — 9y
Ad

Answer this question