VividNeon
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 1607 |
|
|
| 18 Jul 2014 04:40 PM |
| I'm trying to convert a string value that reads "m:ss:msmsms(i.e. 0:23:374)" to a number (by taking out the colons, i.e. 023374). I would THEN like to find the first number, put a colon after it, and then find the third number and put a colon after it. Is this at all possible??? |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 18 Jul 2014 04:51 PM |
Sure. I'm not sure what the best way to do this is, or if there even is a method that is considered best, but what you would do is some string manipulation. This page will prove useful: http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation I would take the string and iterate through each character looking for the colon. string.sub creates a substring, so that will be useful for grabbing the individual parts separated by the colons. Then use the concatenation operator on the substrings (..) to combine them. |
|
|
| Report Abuse |
|
|
|
| 18 Jul 2014 04:54 PM |
--c:
f = {"0",":","23",":","374"}
for i=1,#f do if f[i] == ":" then table.remove(f,i) end end print(table.concat(f))
|
|
|
| Report Abuse |
|
|
VividNeon
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 1607 |
|
|
| 18 Jul 2014 05:38 PM |
| How can you find where to put the colons when the numbers are printed like "023374"? |
|
|
| Report Abuse |
|
|
VividNeon
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 1607 |
|
| |
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 18 Jul 2014 08:24 PM |
| I could probably do it if I thought for a second, but why in the world would you want to do that? That's like converting 12:30 pm to 1230, which doesn't make sense. |
|
|
| Report Abuse |
|
|
VividNeon
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 1607 |
|
|
| 18 Jul 2014 08:52 PM |
| For a DataStore leaderboard. |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 18 Jul 2014 09:18 PM |
That's an interesting way to store that. I assume, since you had to convert it to mm:ss:ms form, that you initially had the seconds that the player was there. Why not store the raw seconds instead and just do the converting when you need to display it? |
|
|
| Report Abuse |
|
|
VividNeon
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 1607 |
|
|
| 19 Jul 2014 09:06 AM |
| Because on the DataStore leaderboard script, the score is one value. If I can somehow make three scores for one DataStore, that would be great... |
|
|
| Report Abuse |
|
|
VividNeon
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 1607 |
|
| |
|
|
| 19 Jul 2014 09:53 AM |
| This messed up my brain and i came with the same script as super. |
|
|
| Report Abuse |
|
|
ohno1112
|
  |
| Joined: 23 Mar 2013 |
| Total Posts: 833 |
|
|
| 19 Jul 2014 10:32 AM |
i would do only the parsing to 1 value
m:ss:msmsms(i.e. 0:23:374)"
numbers = 0:23:374
stringa = numbers:sub(1,1)
stringb = numbers:sub(3,4)
stringc = numbers:sub(6,8)
string = ""..stringa..stringb..stringc
print(string)
should print 023374 |
|
|
| Report Abuse |
|
|
|
| 19 Jul 2014 10:51 AM |
local dostuff=function(string) local pos={} for i=1,#string do if string:sub(i,i)==':' then string=string:sub(1,i-1)..string:sub(i+1) pos[#pos+1]=i end end return string,pos end
local string,tab=dostuff('10:10:10') print(string,table.concat(tab,', '))
The table stores the positions of the colons. So you could use more string manipulation to insert a colon to its position, and move everything in front of it over one character.
I'll post a function that does that later after I figure it out. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Jul 2014 12:07 PM |
Remove colons - time = time:gsub(":", ""); Add colons - time = time:sub(1, 1) + ":" + time:sub(2, 3) + ":" + time:sub(4); |
|
|
| Report Abuse |
|
|
VividNeon
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 1607 |
|
|
| 19 Jul 2014 06:25 PM |
| Thanks, cnt. That's what I was looking for. ;3 |
|
|
| Report Abuse |
|
|
VividNeon
|
  |
| Joined: 24 Apr 2012 |
| Total Posts: 1607 |
|
|
| 19 Jul 2014 06:26 PM |
| Thank you all, as well. Everything is much appreciated! ^.^ |
|
|
| Report Abuse |
|
|