|
| 12 Oct 2016 04:42 PM |
Ahahahaha, how would I do that?
e.g.
"food"
becomes
"Food" |
|
|
| Report Abuse |
|
|
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 |
|
|
| |
|
|
| 12 Oct 2016 04:46 PM |
string = "food"
string.sub(string,1,1) = string.sub(string,1,1):upper() |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
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 |
|
|
|
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Oct 2016 04:51 PM |
| x = x:sub(1,1):upper() .. x:sub(2) |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2016 04:52 PM |
| ############################################################################################## |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 12 Oct 2016 04:54 PM |
Like this?
string = string:sub(1,1):upper() |
|
|
| Report Abuse |
|
|
|
| 12 Oct 2016 04:54 PM |
| ################################################################################# |
|
|
| Report Abuse |
|
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 12 Oct 2016 05:50 PM |
| I don't understand why people answer questions that have already been answered more than once. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|