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: Make the first letter of a string uppercase?

Previous Thread :: Next Thread 
Intended_Pun is online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
12 Oct 2016 04:42 PM
Ahahahaha, how would I do that?

e.g.

"food"

becomes

"Food"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Oct 2016 04:45 PM
x:sub(1,1):upper() .. x:sub(2)

You could also use gsub but I think it's better to keep it simple
Report Abuse
Intended_Pun is online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
12 Oct 2016 04:46 PM
Is x the string?
Report Abuse
Gusmanaks_Dad is not online. Gusmanaks_Dad
Joined: 01 Mar 2016
Total Posts: 58
12 Oct 2016 04:46 PM
string = "food"

string.sub(string,1,1) = string.sub(string,1,1):upper()
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Oct 2016 04:46 PM
yeah
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Oct 2016 04:47 PM
yeah to x being the string, not to that guy
gusmanack's code wouldn't even work at all lmao
Report Abuse
Intended_Pun is online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
12 Oct 2016 04:50 PM
Cnt can you please explain that in more detail, I have no idea what to do with it.

x:sub(1,1):upper() .. x:sub(2)

"Expected Identifier". I'm not sure what to do.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Oct 2016 04:51 PM
x = x:sub(1,1):upper() .. x:sub(2)
Report Abuse
Gusmanaks_Dad is not online. Gusmanaks_Dad
Joined: 01 Mar 2016
Total Posts: 58
12 Oct 2016 04:52 PM
##############################################################################################
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
12 Oct 2016 04:53 PM
local s = 'my string'
s = s:gsub(s:sub(1,1),s:sub(1,1):upper())
print(s)

>>My string


Report Abuse
Intended_Pun is online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
12 Oct 2016 04:54 PM
Like this?

string = string:sub(1,1):upper()
Report Abuse
Gusmanaks_Dad is not online. Gusmanaks_Dad
Joined: 01 Mar 2016
Total Posts: 58
12 Oct 2016 04:54 PM
#################################################################################
Report Abuse
Intended_Pun is online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
12 Oct 2016 04:55 PM
Thanks time
Report Abuse
Gusmanaks_Dad is not online. Gusmanaks_Dad
Joined: 01 Mar 2016
Total Posts: 58
12 Oct 2016 04:55 PM
Can't #### #### for some reason, but not that wouldn't work, it'd just get first letter.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Oct 2016 04:57 PM
I literally gave you the code on how to do it

x = "whatever"
x = x:sub(1,1):upper() .. x:sub(2)

And his wouldn't work, it'll replace all occurrences
Report Abuse
Intended_Pun is online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
12 Oct 2016 04:58 PM
Cnt, I have no idea what to do with this ".. x:sub(2)" part. What am I supposed to do there?

Report Abuse
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
12 Oct 2016 04:59 PM
sub will obviously (if you hadnt known) 'split' the string so that it starts at position A-1 and ends at position B+1

print(("hello world!"):sub(1,1))

is a string split to the range of the 1st character to the 1st
it ranges from the character behind it to the character in front which only includes that character

print(("hello world!"):sub(1,1):upper() .. ("hello world!"):sub(2))
converts the first character into uppercase and combines it with concatenation to the rest of the string
Report Abuse
Intended_Pun is online. Intended_Pun
Joined: 10 Aug 2016
Total Posts: 4384
12 Oct 2016 04:59 PM
Oh wait nevermind it works in the command bar... It must just be the script editor. Thanks.
Report Abuse
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
12 Oct 2016 05:48 PM
local msg = "hello there"
if msg:match("^[%w]+") then msg = msg:sub(1, 1):upper() .. msg:sub(2, #msg) end


( ͡• ◡ ͡•) -=[ RAP: 403,671 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
12 Oct 2016 05:50 PM
I don't understand why people answer questions that have already been answered more than once.
Report Abuse
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
12 Oct 2016 05:53 PM
@AggressiveCatch
Usually I don't tend to read the responses until I've posted.


( ͡• ◡ ͡•) -=[ RAP: 403,589 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
Kodran is not online. Kodran
Joined: 15 Aug 2013
Total Posts: 5330
12 Oct 2016 05:53 PM
ok calm the darn heck down mate!

first of all, why do you need to match the first letter at all, calling string.upper on a number or other character won't change anything.

secondly, why would you use %w, that matches with digits as well!

alright onto the next thing, why do you need the set? you only specified one type of character!

next, why do u need the + quantifier, like it would match a1 and aa1 but like didn't you only do the match to make sure the first char was a letter? (which u failed at)

ok also, u dont need to specify the second argument of sub on the second part, if no argument is given it goes to the end of the string.

phew


Report Abuse
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
12 Oct 2016 06:07 PM
if you are making commands:

functions = {
kill = function() print("yay") end
}

local command = cmd:match("%S+")
if command then command=command:match(":%a+") end

if command and functions[command:sub(2 )] then functions[command:sub(2 )]() end
Report Abuse
DurstAuric is online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
12 Oct 2016 06:27 PM
@Kodran
I don't know. I'm not a great coder okay? Especially when it comes to strings.. I'll fix my mistake then.

local msg = "hello there"
if msg:match("^%a") then msg = msg:sub(1, 1):upper() .. msg:sub(2) end


( ͡• ◡ ͡•) -=[ RAP: 403,521 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
Wunder_Wulfe is not online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
15 Oct 2016 10:46 PM
^ that checks if the first character is a alphabetical character.

%a is any alphabetical character
^ when not used in a set is check the beginning

if you want to make the first letter capital:

local match = yourString:find("%a")
if match then
yourString = yourString:sub(1,match) .. yourString:sub(match+1)
end
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