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: String help

Previous Thread :: Next Thread 
HatHelper is not online. HatHelper
Top 25 Poster
Joined: 02 Mar 2009
Total Posts: 46305
17 Jul 2011 10:08 PM
a = "abc123456789"

How would I find if 'a' has string 'c1', and print the next 10 characters?
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
17 Jul 2011 10:11 PM
local start, end = string.find(a, "c1")
string.sub(a, start, (end-start)+10)
Report Abuse
L2000 is not online. L2000
Joined: 03 Apr 2008
Total Posts: 77448
17 Jul 2011 10:12 PM
I'd use 'for i = 1,#a do' and check if the current string is c and 1. If it is, then print the next 10 characters.


for i = 1,#a do
if string.sub(a, i, i)=="c" then
if string.sub(a, i+1, i+1)=="1"then
print(string.sub(a, i+2, i+12))
end
end
end
Report Abuse
BladzofChaos70 is not online. BladzofChaos70
Joined: 27 Sep 2008
Total Posts: 2550
17 Jul 2011 10:13 PM
for i=1, string.len(a) do
if ((string.sub(a),i,i+1)=="c1") then
print(string.sub(a),i+2)
end
end
Report Abuse
HatHelper is not online. HatHelper
Top 25 Poster
Joined: 02 Mar 2009
Total Posts: 46305
17 Jul 2011 10:13 PM
L2000 that's extremely inefficient. It what I would have done a year ago :I
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
17 Jul 2011 10:18 PM
*Facepalm*

Excuse me, I need to reread the string functions part of the wiki.

local start, endf = string.find(a, "c1")
string.sub(a, start, endf+10)

Would work correctly, I believe.
Report Abuse
HatHelper is not online. HatHelper
Top 25 Poster
Joined: 02 Mar 2009
Total Posts: 46305
17 Jul 2011 10:19 PM
Thanks.
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
17 Jul 2011 10:22 PM
a = "abc123456789"
print(a:match("c1(..........)"))

But this method will print nil if there aren't 10 chars in front. xP
Report Abuse
BladzofChaos70 is not online. BladzofChaos70
Joined: 27 Sep 2008
Total Posts: 2550
17 Jul 2011 10:26 PM
@swmanic

I completely forgot about string.find! Thank you for not only helping him but reminding me of a very useful string function XD.
Report Abuse
HatHelper is not online. HatHelper
Top 25 Poster
Joined: 02 Mar 2009
Total Posts: 46305
17 Jul 2011 10:30 PM
Thats even better ElectricAxel.
Report Abuse
HatHelper is not online. HatHelper
Top 25 Poster
Joined: 02 Mar 2009
Total Posts: 46305
17 Jul 2011 10:32 PM
I don't remember how string.gsub worked in the way I wanted. How do I remove all characters other than numbers from a string?
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
17 Jul 2011 11:03 PM
string.gsub(a, "%d", "")
Report Abuse
ElectricAxel is not online. ElectricAxel
Joined: 15 May 2009
Total Posts: 16239
17 Jul 2011 11:04 PM
My bad, %D (capital meants NOT)

string.gsub(1, "%D", "")
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