generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Trim Part of Variable

Previous Thread :: Next Thread 
futbal11 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. futbal11
Joined: 05 Jun 2014
Total Posts: 146
03 Sep 2015 07:33 PM
anyone?
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
03 Sep 2015 07:36 PM
x = x:sub(1,x:find("%s"))
Report Abuse
East98 is not online. 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 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
03 Sep 2015 07:42 PM
oh
my
god
Report Abuse
futbal11 is not online. futbal11
Joined: 05 Jun 2014
Total Posts: 146
03 Sep 2015 07:50 PM
neither of them work for me :/
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
03 Sep 2015 07:51 PM
show me your code
Report Abuse
futbal11 is not online. 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 is not online. 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 is not online. 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
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image