How to get separate strings from one received string?

Hello!

So, I am trying to get data from Trello.
All this is successful and string from one card is sent.
From Card’s description which is for example:
SloveniaVideo, test, 123

From that, I want to get separate strings. Like. I just started today with string.split, etc.
Basically, from separate strings (for example if we would get 3 strings from one) I want to create 3 Text Labels, each with data from one string.
It should look like that:

Label 1:
SloveniaVideo

Label 2:
Test

Label 3:
123

So:

  1. How to even get this specified so Roblox gives you more strings from one, received;
  2. How to specify numbers. Probably like if I would have variable and I would say variable[1] or something like that. Any other ideas?

Thank you!
SloveniaVideo

1 Like

Hello, as i can see, you need to separate the strings, you can do an loop with “for” like:
local strings = {“SloveniaVideo”, “test”, 123}
for i=1, #strings do
print(strings[i])
end
Edit: Using that u can separate the strings without use numbers, the loop will be the number to separate them

1 Like

Simple, just do this to return a table of strings split by every comma:

local data = string.split(str,”,”) 
1 Like

I know this is dumb question, but I always kept asking my self about it:
What is i=1 and #strings thing?

Also. How would I automatically add "" symbols because I don’t have these in my Trello card’s desc.

When you return the data is returns as a table so basically

local DataTable = {SloveniaVideo, test, 123} -- returned json table
for i,v in pairs(DataTable) do
   print(i,v) -- i = "Index" = position value, v = Item e.g. 
end

Output

1 SloveniaVideo
2 test
3 123

From what I have gathered from the post you made if its returning a string value you can use string.split() like so.

local RetString = "SloveniaVideo,test,123"
local SplitString = RetString:split(",")

for i,v in pairs(SplitString)do
    print(i,v)
end
1 Like

I’ve tried that but I got this error:
bad argument #1 to ‘split’ (string expected, got table)

If you are getting a table, then it is not a single string, and can just do Table[1], if it is a string within a table you will have to specify the index and then use string.split()

1 Like

The i=1 was the first string at the table like table = {“Game”, “Game2”}, the 1 will be the [“Game”], #strings was the number of strings at the table so it will return the number of strings and print out the string using the number of the for i, if i=0 the string gonna be nil thats the why it starts in 1 and not in 0, so the i was the number of the current string in a table and #strings is what get the number of strings at the table.

1 Like

From the thing from the Trello card (SloveniaVideo,test,123) and in for in pairs loop,
I got this:

1 SloveniaVideo,test,123

1 Like

As I mentioned before, use the code I gave you but put Table[1] instead of str.

From this code, when I specify card’s desc I still got CardID. When I specify desc just in print(), I get normal output.

1 Like

Wait so its returning the string in a table?

You are returning a table, with strings in them, and are trying to separate them, this means that you will have to index the string which in your case is the first index.

So if we did Table[1] it would give us the combined string.

We then use string.split() to split this string into a separate table.

With this NEW table we can now get the separate strings using NewTable[1], NewTable[2], etc

1 Like

When I want to get card’s desc normally by doing following:
print(cardVariable.desc) I get description

but when I put cardVariable.desc in table or string.split for example, I just get CardID (some random numbers which I get and then from ID, cardVariable come)

1 Like

Oh so it is a returning the string in a table

local RetString = {"SloveniaVideo,test,123"}
local SplitString = RetString[1]:split(",")

for i,v in pairs(SplitString)do
    print(i,v)
end

Okay. So due to probably TrelloAPI error, I now made script that adds Trello’s Card Desc into String Value and then, this script which you sent me, collects that Value’s value and uses it.

I just removed [1] due to this error:

attempt to index field ‘?’ (a nil value)

However, after I removed that, everything is fine now!
Thank you!

I have one more question:
how would I specify value?
Like, I want to add each value in one Text Label.
For example, first string would be in Label 1, second one in second label, etc

1 Like

With the code I provided to you earlier the values would be separated with the v value in the for loop it depends on how you have your code setup currently in order to do this.

I’ve tried this, however, it’s not working:

for i,v in pairs(SplitString) do
		local gui = script.Rank
		gui.Parent = script.Parent.SurfaceGui.ScrollingFrame
		print(v[1])
		gui.Val1.Text = v[1]
		gui.Val2.Text = v[2]
		gui.Val3.Text = v[3]
	end

Return in output is nil and error: bad argument #3 to 'Text' (string expected, got nil)

1 Like

Maybe you can share the setup of your hierarchy so I can get a better understanding of the constraints the code will be working with. I am unsure of you are only gonna be returning 3 strings every time so that is why I am asking this question.

It returns a string when I do like print(i, v) but I don’t know how do I specify all returned strings with numbers.
Like first one would be 1 and first Label etc.

1 Like