dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
|
| 01 Mar 2014 04:03 PM |
ok if I have basePart1,2 or basePart429,135316 or anything like that how would I isolate just the coordinates after so like
basePart1,2 >1,2
or
basePart429,135316 >429,135316
notice there is no space in the string or anything
thanks in advance |
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 01 Mar 2014 04:11 PM |
This should work.
a = "basePart429,135316" function findChar(a, pos) for i = pos, 0, -1 do if not tonumber(a:sub(i, i)) then return i+1 end end end local comma = a:find(",") print(a:sub(findChar(a, comma), comma-1)) print(a:sub( comma)) |
|
|
| Report Abuse |
|
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
|
| 01 Mar 2014 04:27 PM |
I changed all a's to the variable word because I already have an a xD but heres what happens when I try it:
word="basePart1632,13136" function findChar(word, pos) for i = pos, 0, -1 do if not tonumber(word:sub(i, i)) then return i+1 end end end local comma = word:find(",") print(word:sub(findChar(word, comma), comma-1)) print(word:sub( comma))
> >,13136
I want it to print 1632,13136 also the first print shows up blank... |
|
|
| Report Abuse |
|
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
| |
|
Disti15
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 2652 |
|
|
| 01 Mar 2014 05:12 PM |
name = basePart429,135316 name = string.sub(name, 9, string.len(name)) print(name) |
|
|
| Report Abuse |
|
|
Disti15
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 2652 |
|
|
| 01 Mar 2014 05:13 PM |
name = "basePart429,135316"
forgot that, sorry. |
|
|
| Report Abuse |
|
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
|
| 01 Mar 2014 05:21 PM |
k thanks, one more xD say I have like 20 different numbers here, so 1,1:316.2,2:31513.2,3:42698246
(not really going to be 20 but as many as I need, I need to compact data store lol)
how would I make it so it returns a>1,1 b>316
a>2,2 b>31513
a>2,3 b>42698246
for each one? You can change the symbols that are commas, numbers, and periods, but the .s represent different "ab" sets |
|
|
| Report Abuse |
|
|
Disti15
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 2652 |
|
|
| 01 Mar 2014 05:25 PM |
ls = 1 n = 1 data = "1,1:316.2,2:31513.2,3:42698246" for i = 1, string.len(data) do if string.sub(data, i, i) == ":" then print("a"..n..":"..string.sub(data, ls, i-1)) ls = i+1 elseif string.sub(data, i, i) == "." then print("b"..n..":"..string.sub(data, ls, i-1)) ls = i+1 n = n+1 end end
There you go.
|
|
|
| Report Abuse |
|
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
| |
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
| |
|
Voidition
|
  |
| Joined: 14 Jul 2012 |
| Total Posts: 1849 |
|
| |
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
|
| 01 Mar 2014 05:33 PM |
| I am not ripping off minecraft... this has nothing to do with minecraft |
|
|
| Report Abuse |
|
|
Disti15
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 2652 |
|
|
| 01 Mar 2014 05:34 PM |
Ooops, sorry, there you go:
ls = 1 n = 1 data = "1,1:316.2,2:31513.2,3:42698246"
for i = 1, string.len(data) do if string.sub(data, i, i) == ":" then print("a"..n..":"..string.sub(data, ls, i-1)) ls = i+1 elseif string.sub(data, i, i) == "." then print("b"..n..":"..string.sub(data, ls, i-1)) ls = i+1 n = n+1 elseif i == string.len(data) then print("b"..n..":"..string.sub(data, ls, i)) end end |
|
|
| Report Abuse |
|
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
|
| 01 Mar 2014 05:35 PM |
| lol no need to say sorry, I should be saying sorry for being too stupid to be able to understand the wiki page on string manipulation |
|
|
| Report Abuse |
|
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
|
| 01 Mar 2014 05:42 PM |
local brick = "brick2203939"
for i in string.gmatch(brick, "%d*") do print(i) end
|
|
|
| Report Abuse |
|
|
Bebee2
|
  |
| Joined: 17 May 2009 |
| Total Posts: 3985 |
|
|
| 01 Mar 2014 05:46 PM |
| ^ Problem being he has commas =P. |
|
|
| Report Abuse |
|
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
| |
|