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: Removing word from a string

Previous Thread :: Next Thread 
KiyomizuOkami is not online. KiyomizuOkami
Joined: 31 Jul 2008
Total Posts: 297
18 Dec 2015 11:32 AM
Say I have a string,

x = "This is my string"

How would I remove the last word from that, and reprint it?
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
18 Dec 2015 11:43 AM
print(x:gsub("%a-$",""))

it would stop at anything that's not a letter though
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
18 Dec 2015 11:45 AM
print(x:gsub(" [%a%d]-$",""))

that would remove the first whitespace found and all the letters & digits
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
18 Dec 2015 12:37 PM
Ozzy, just use %w, it matches letters and numbers. e_e

But frankly, I would go with
%S+$
it matches any character that isn't a whitespace.
Report Abuse
KiyomizuOkami is not online. KiyomizuOkami
Joined: 31 Jul 2008
Total Posts: 297
18 Dec 2015 12:43 PM
Thanks! However, if I have a string such as
x = "Blue Wooden Maru Katana 3565232"
How do I simply print, Blue Wooden Maru Katana, without the numbers at the end?
Report Abuse
b6e is not online. b6e
Joined: 14 Nov 2014
Total Posts: 33
18 Dec 2015 12:46 PM
local name, otherstuff = x:match("^(.-)%s-(%d*)$")

-yo recipes
Report Abuse
KiyomizuOkami is not online. KiyomizuOkami
Joined: 31 Jul 2008
Total Posts: 297
18 Dec 2015 12:57 PM
That just printed the number at the end, not the words before the number?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
18 Dec 2015 02:08 PM
x = "Blue Wooden Maru Katana 3565232"
x = x:match("(.-)%S+$");
print(x)
Report Abuse
GRAGGER2001 is not online. GRAGGER2001
Joined: 05 Apr 2009
Total Posts: 2043
18 Dec 2015 02:48 PM
"x = x:match("(.-)%S+$")" Is this new?
Report Abuse
b6e is not online. b6e
Joined: 14 Nov 2014
Total Posts: 33
18 Dec 2015 03:41 PM
@cnt that's just going to print an empty string as %S+ is greedy and .- is not

-Commit committed....
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
18 Dec 2015 04:04 PM
You're stupid, you don't understand how patterns work when you assume you do so you don't bother to test it.
(.-) (.*) or (.+) all work here and it's obvious why.
Mine _will_ print "Blue Wooden Maru Katana"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
18 Dec 2015 04:05 PM
@GRAGGER the match function is old
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