futbal11
|
  |
| Joined: 05 Jun 2014 |
| Total Posts: 146 |
|
|
| 03 Sep 2015 06:54 PM |
if you have a variable x x = "Dog Cat Mouse"
is there a way I could trim the variable to cut it off once the first space occurs? (Now x = "Dog")
Thank you. |
|
|
| Report Abuse |
|
|
East98
|
  |
| Joined: 17 Jun 2012 |
| Total Posts: 418 |
|
|
| 03 Sep 2015 07:02 PM |
| http://wiki.roblox.com/index.php?title=Function_Dump/String_Manipulation |
|
|
| Report Abuse |
|
|
futbal11
|
  |
| Joined: 05 Jun 2014 |
| Total Posts: 146 |
|
|
| 03 Sep 2015 07:08 PM |
| i don't know if I missed something but I couldn't see a way to remove all characters after a space :/ |
|
|
| Report Abuse |
|
|
East98
|
  |
| Joined: 17 Jun 2012 |
| Total Posts: 418 |
|
|
| 03 Sep 2015 07:17 PM |
| you would have to set up a function that locates the first space by checking each character starting at the beginning of the string. Then when it finds the space you trim it based on the distance that it found this space from the beginning of the string |
|
|
| Report Abuse |
|
|
futbal11
|
  |
| Joined: 05 Jun 2014 |
| Total Posts: 146 |
|
|
| 03 Sep 2015 07:18 PM |
| could you help me do that or naww |
|
|
| Report Abuse |
|
|
futbal11
|
  |
| Joined: 05 Jun 2014 |
| Total Posts: 146 |
|
| |
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
East98
|
  |
| Joined: 17 Jun 2012 |
| Total Posts: 418 |
|
|
| 03 Sep 2015 07:39 PM |
local str1 = "Looking for the first space"
function findFirstSpace(str) local search = 0 local found = false repeat search = search + 1 if string.sub(str,search,search) == " " then print("Found space at "..search) found = true else print(string.sub(str,search,search).." is not a space") end until found == true or search == #str if found then return search else return nil end end
function trim(str) local len = findFirstSpace(str) if len then local newStr = string.sub(str,1,len-1) print(newStr) return newStr end end
trim(str1) |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
futbal11
|
  |
| Joined: 05 Jun 2014 |
| Total Posts: 146 |
|
|
| 03 Sep 2015 07:50 PM |
| neither of them work for me :/ |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
| |
|
futbal11
|
  |
| Joined: 05 Jun 2014 |
| Total Posts: 146 |
|
|
| 03 Sep 2015 07:53 PM |
--order = 0 PLAYERS = {} game.Players.PlayerAdded:connect(function(plr) --order = order + 1 table.insert(PLAYERS, plr.Name) end)
game.Players.PlayerRemoving:connect(function(plr) for i,v in pairs(PLAYERS)do if v == plr.Name then table.remove(PLAYERS,i) break end end
end)
while wait(3) do local x = table.concat(PLAYERS ' ') x = x:sub(1,x:find("%s")) print(x) end |
|
|
| Report Abuse |
|
|
rayk999
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 4705 |
|
|
| 03 Sep 2015 07:54 PM |
local x = table.concat(PLAYERS ' ') should be local x = table.concat(PLAYERS, ' ') |
|
|
| Report Abuse |
|
|
futbal11
|
  |
| Joined: 05 Jun 2014 |
| Total Posts: 146 |
|
|
| 03 Sep 2015 08:00 PM |
| lmao I had it before with a comma but I think I removed it on accident at some point and thank you! :D |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2015 08:05 PM |
local x = "Miley was good?"
local y = string.sub(x,1,string.find(x," ")-1)
print(y) |
|
|
| Report Abuse |
|
|