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

What use/ What are Strings used for, if at all?

Asked by 7 years ago

What I'm really trying to ask is: What use do strings have at all? I've seen them appear in some questions with string:lower() etc... If someone could explain please explain what they are used for it would be much obliged. Oh and please don't say "To change the name of something".

3 answers

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

Strings

Strings are simply a way of representing text. They have many, many uses.
Some of these uses are:
* Getting input from a player as text, for example a name.
* Telling the player something, such as a message from another character.
* By the game, for things such as (as you mentioned) names of objects, a player's chosen class, the current game state (intermission, in a match), etc.

In short, they're used for when you want to represent anything as text. Once you start using tables and dictionaries, you'll really come to appreciate strings.

Ad
Log in to vote
1
Answered by 7 years ago

What are Strings?

Well, it might surprise you to know that strings aren't prices of yarn or things made of sheep's intestines. At least not in programming.

A string is like a message, or sequence of characters. For example, the following would not work because we're not using a string.

local x = I love coding!
print(x)

The only way to print "I love coding", is by using a string.


Making and Using Strings

There are many, many ways to represent a string in Lua. Here's a fun answer on SH you should read.

Normally, we make strings by using Quotation Marks.

local x = "I love coding!"
print(x)

Strings can be numbers also. It really doesn't matter what you put in a string.

local z = "123"

print(z)
print(123)


-- OUTPUT
123
123

Where you often see strings used

You see strings used everywhere. The names of objects are strings, tons of functions take strings, dictionaries use strings a ton, and basically everywhere you look, you'll see strings used.

You can understand why string would be used. Without them, we would have to use numbers for everything, and things would be much more confusing.


If you have any questions, feel free to ask me.

Good Luck!

If I helped, please don't forget to accept my answer :3
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Strings are used in manipulation of variables / tables. Their objective is to change the variable into another form or version of it.

For example:

print(string.byte("d")) --Returns 100 (Returns the number form of a letter or word)
print(string.char(100)) --Does the exact opposite, returns a letter based on a number
print(string.lower("HELLO")) --Returns the lowercase version of the string (hello) This also works in reverse with string.upper
print(string.len("abcdefg")) --Counts the number of letters in the string (7)

These are just a few of the types of ways strings can be manipulated. You can read more about all of them and the way that they work right here

Answer this question