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 » Scripting Helpers
Home Search
 

Re: "Subtracting" String Values?

Previous Thread :: Next Thread 
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
02 May 2012 07:03 PM
You can "Add" strings together using .. but can you "Subtract" them?
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
02 May 2012 07:07 PM
What do you mean subtract?
Report Abuse
Drenkus is not online. Drenkus
Joined: 03 May 2009
Total Posts: 2380
02 May 2012 07:21 PM
You can, with string.sub()
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
02 May 2012 08:07 PM
@Drenkus

No you can't. That is for grabbing a part of a string from point "A" to point "B". That isn't subtracting, that's separating. In order to subtract, use gsub().

local s = "Hello World!"
print(string.gsub(s, "World", "!!"))

--It removes World and replaces it with !!.

--It prints: Hello!!!
--If you want to REMOVE World, do this:

string.gsub(s, "World", "")

With a Five-Guys burger in my hands, I am now invincible!
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
04 May 2012 06:41 AM
And for "Adding"? gadd()?
Report Abuse
Jellyfish403 is not online. Jellyfish403
Joined: 12 May 2010
Total Posts: 951
04 May 2012 06:47 AM
I'll use .. for "adding".
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
04 May 2012 07:01 AM
Subtract 'World' from "Hello World!':

string.gsub("Hello World!","World","")

Add 'World' to "Hello !":

string.gsub("Hello !"," "," World")
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
04 May 2012 05:24 PM
@Bunny

Terribly inefficient. It would put it into the first space. The best you could do is this:

string.format("Hello %s !", "World") --Hello World !
string.format("This is a %s full of %s", "world", "tacos.") --This is a world full of tacos.

With a Five-Guys burger in my hands, I am now invincible!
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
04 May 2012 10:20 PM
wow sorry.
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
05 May 2012 09:01 AM
Link to string formatting:

http://wiki.roblox.com/index.php/String_Formatting

Annoying the crap out of you, one word at a time. -Says suoicodilaipxecitsaligirfilacrepus repeatedly-
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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