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
 

Re: Formatting a String

Previous Thread :: Next Thread 
xSoulSpectrumx is not online. xSoulSpectrumx
Joined: 30 Nov 2011
Total Posts: 2976
06 Oct 2016 01:46 AM
Simple question, though I asked something similar before.

Let's say I have this string:

"C:2,A:7,S:45,T:29,L:0,E:2"

I want to turn this into five variables.

C,A,S,T,L,E = 2,7,45,29,0,2

What is the correct way to do this?
Report Abuse
xSoulSpectrumx is not online. xSoulSpectrumx
Joined: 30 Nov 2011
Total Posts: 2976
06 Oct 2016 01:47 AM
Six I mean, not five.
Report Abuse
Refactorize is not online. Refactorize
Joined: 02 Oct 2016
Total Posts: 172
06 Oct 2016 01:48 AM
Not entirely sure if there's a better way of doing this, but use loops and setfenv() or shared.
Report Abuse
xSoulSpectrumx is not online. xSoulSpectrumx
Joined: 30 Nov 2011
Total Posts: 2976
06 Oct 2016 01:52 AM
I can't see how something like that meant for most metatables it looks like is meant to separate this string. A loop maybe but in what fashion to break it apart? In context I want the numbers.
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
06 Oct 2016 02:03 AM
Why the heck would you use setfenv here?

local String = "C:2,A:7,S:45,T:29,L:0,E:2"
for name, digit in String:gmatch("(%a):(%d)") do
getfenv()[name] = digit
end

print(C) -- 2
Report Abuse
KreoBox is not online. KreoBox
Joined: 24 Aug 2016
Total Posts: 356
06 Oct 2016 02:08 AM
"I can't see how something like that meant for most metatables it looks like is meant to separate this string."

What? Setfenv has nothing to do with metatables.


pastebin /baKWg7L6
Report Abuse
CodeBreadpudding is not online. CodeBreadpudding
Joined: 24 Aug 2016
Total Posts: 1286
06 Oct 2016 08:14 AM
Look up string patterns in my help desk I'm about to post.
Report Abuse
xSoulSpectrumx is not online. xSoulSpectrumx
Joined: 30 Nov 2011
Total Posts: 2976
06 Oct 2016 11:12 AM
The getfenv didn't get all digits so I ended up doing this.

local String = "C:2,A:7,S:45,T:29,L:0,E:2"

_,Community,_,Agility,_,Service,_,Teamwork,_,Leadership,_,Endurance = String:match("([^:]+):(%d+),([^:]+):(%d+),([^:]+):(%d+),([^:]+):(%d+),([^:]+):(%d+),([^:]+):(%d+)")

print(Community,Agility,Service,Teamwork,Leadership,Endurance)
Report Abuse
iDerpyDogez is not online. iDerpyDogez
Joined: 05 Feb 2012
Total Posts: 1781
06 Oct 2016 11:33 AM
@xsoul u couldve just done

local String = "C:2,A:7,S:45,T:29,L:0,E:2"
for name, digit in String:gmatch("(%a+):(%d+)") do
getfenv()[name] = digit
end




𝒷𝓁𝑜𝒷𝒻𝒾𝓈𝒽 𝒶𝓇𝑒 𝑔𝑜𝒾𝓃𝑔 𝓉𝑜 𝒷𝑒 𝒷𝓇𝒾𝒸𝓀𝓈 𝒻𝑜𝓇 𝓂𝓎 𝓌𝒶𝓁𝓁; 𝓉𝒶𝓇𝒹𝒾𝑔𝓇𝒶𝒹𝑒𝓈 𝒶𝓇𝑒 𝑔𝑜𝒾𝓃𝑔 𝓉𝑜 𝒷𝑒 𝓉𝒽𝑒 𝑔𝓁𝓊𝑒 𝒻𝑜𝓇 𝓂𝓎 𝓌𝒶𝓁𝓁
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
06 Oct 2016 01:01 PM
I didn't realize you wanted all the digits, mb
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
06 Oct 2016 01:28 PM
local String = "C:2,A:7,S:45,T:29,L:0,E:2"
for Variable, Value in String:gmatch("(%S+):(%S+),?") do -- Almost correct.
getfenv()[Variable] = Value
end


( ͡• ◡ ͡•) -=[ RAP: 414,347 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
06 Oct 2016 01:30 PM
That's not even sort of right.

iderpydogz already solved it (although maybe you wanna tonumber all the digits)
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
06 Oct 2016 01:31 PM
I was trying to be more practical in the event that a variable doesn't start with a digit.


( ͡• ◡ ͡•) -=[ RAP: 413,739 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
06 Oct 2016 01:32 PM
that moment when the gsub has spoken
print(("i am cool"):gsub("am","not"))
Report Abuse
cntkillme123 is not online. cntkillme123
Joined: 10 Feb 2013
Total Posts: 539
06 Oct 2016 01:36 PM
You'd want to separate them by : not by %s.
something like
",?(.-):([^,]+)"
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
06 Oct 2016 01:38 PM
I see. I'm fairly new to string patterns as they've always confused me.


( ͡• ◡ ͡•) -=[ RAP: 413,759 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
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