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

String Manipulation explanation ?

Asked by 7 years ago
Edited 7 years ago

How do I use string manipulation to find something from a the result of a HTTP request? Explains/Tutorials/Different situations will greatly appreciated.

Don't put Explains/Tutorials/Different situations from ROBLOX wiki.

0
I guess taking 40 minutes to write an answer, I did answer your question on how to FIND certain parts of HTML with string manipulation. I hope you at least upvoted my answer, because when people do hard work and don't get recognition it hurts self-esteem, and we lose people using this site. EzraNehemiah_TF2 3552 — 7y

2 answers

Log in to vote
4
Answered by 7 years ago

What you could try

String manipulation is key when getting the Async from a website. What you could use is string.match.


What does string.match do?

You give string.match a string like so: local text = "Hello" and if you use string.match, the second argument is what part of the code are you looking for? string.match(text, "ello") and what it will give you is "ello". If it cannot find ello, it returns nil.


How can you use this with HTTPService

This following code was made by HungryJaffer. This is a blog posts made almost exactly last year(8/28/2015). This blog tells you about how you can get a player's reputation through HTTPService. Give it a read, remember: you don't have to ask your answer as soon as something goes wrong, do some research. The blog is a great place.


Can his code more?

In case you do not understand the blog, or if the blog is TL;DR then here's an explanation of each line of code:

function getRep(Player) --Function starts; use the player name
    local nom = Player -- Create a string variable of the name
    local link  = "https://scriptinghelpers.org/user/".. nom -- We will Concatenate the link and the    name. 
    local Service = game:GetService("HttpService") --HttpService
    local html = Service:GetAsync(link, false)  --the link is given and it's not cached
    local string = [[<div>%d+ reputation</div>]] --As you may know, the line inside the double brackets are written in a different coding language: HTML
    local snippet = html:match(string) --In all the HTML coding, find this ONE line of code.
    Reputation = (snippet:match("%d+"))--In that one specific line of code, see how much reputation the player has

    return ("Player has " .. Reputation .. " reputation on Scripting Helpers")--return this string
end

print(getRep("LordDragonZord"))

It will output:

Player has 479 reputation on Scripting Helpers



Hope it helps!

0
Note how it says, "Player has 479 reputation on Scripting Helpers" *wink wink* EzraNehemiah_TF2 3552 — 7y
Ad
Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

String manipulation is like turning a string into something else. For example, if I use string.reverse() on a string it will reverse the string, you've just done string manipulation. I don't know what you mean by find something from a result of a HTTP request, but I'll just explain some other stuff that have to do with string manipulation.

Here's some examples of me manipulating string: Let's say I want to put two strings together into one, this is called string concatenating, this is probably how people manipulate string the most. Anyways, here's an example of concatenating

local string1 = "My name is"
local string2 = "Bob."
print(string1..string2)

Output: My name isBob. Here's also another thing with string concatenating: you have to always put a space before the first string you are going to put together, noticed how in the output it turned out to be 'My name isBob.' instead of 'My name is Bob.'? Well we can easily fix that by putting a space before the first string like so:

local string1 = "My name is " -- notice the space after the text?
local string2 = "Bob."
print(string1..string2)

Output: My name is Bob. There are many more ways to manipulate string, because I didn't want to make this answer very long, I just explained one or two ways.

I hoped this help you in some way, and I'm sorry I didn't know what you meant by: find something from a result of a HTTP request

Also, remember to accept my accept my answer if it helped!

Go here if you want to learn more about string manipulation.

0
Take a look at this link for more informations: http://www.lua.org/manual/5.1/manual.html#5.4 Link150 1355 — 7y

Answer this question