How to find the integer after a term in the string?

So I have this string:

Screen Shot 2020-07-04 at 18.38.21

Screen Shot 2020-07-04 at 18.37.03

My question is, how would I get the number 3 after the term “DataStoresUsed” from the whole string?


Solution wise, id imagine @eatfatdie’s method would also work but I did not test, I just found @Rare_tendo’s one neater so went with it.

It is a string not a table unfortunatly :frowning:

Side note, ignore the 115 at the end of the string.

This looks like a JSON table from an HTTP request.

Convert it to a normal table by using JSONDecode()
https://developer.roblox.com/en-us/api-reference/function/HttpService/JSONDecode

Once you do that you should be able to index it like you would with any other table.

2 Likes

i’d do something like this, not sure if it’d work or not

local Table = {}
for w in string.gfind("your string here", ":(%d+)") do
    table.insert(Table, w)
end

gfind iterates over each term that contains digits after :s and the for loop inserts it into a table

if you just want the term after “DataStoresUsed” you can do
string.find("your string here", '"DataStoresUsed":(%d+)')

local dataStoresUsed = str:match("\"DataStoresUsed\":(%d+)")
print(dataStoresUsed)

This seems like JSON, so you could’ve decoded it

1 Like

Unfortunately that does not fit with ym use case since it would involve calling JSONDecode on my same string twice which im not very satisfied with on the efficiency side :frowning:

Why would you need to call JSONDecode twice?

1 Like

As I said, its specific to my use case, im making a datastore that can store a string more then 1,000,000 characters long, so I would have to decode the first segment to find the amount of datastore keys I have to search through, then decode the combined string which includes the original to get my full value.