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 10 years ago

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

1string.len() --The string part
2string.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:

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

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

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

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
10 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:

1local word          = "ABC"
2local firstWay      = string.lower(word)
3local secondWay     = word:lower()
4print(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 — 10y
Ad

Answer this question