Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ How make a function to change the first letter of one English sentence to upper
How make a function to change the first letter of one English sentence to upper
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Lxhd
(27 posts) Bio
|
Date
| Tue 02 Feb 2016 03:05 AM (UTC) |
Message
| I want to make a function by Lua to change the firt letter of one setence or word to upper case,
for examplle:
"i like you" to "I like you"
"woman" to "Woman"
please kindly give me your kind suggestion, thanks a lot. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Tue 02 Feb 2016 04:51 AM (UTC) Amended on Tue 02 Feb 2016 04:52 AM (UTC) by Nick Gammon
|
Message
| For the first letter of a sentence:
foo = string.gsub ("i like you", "^.", string.upper)
print (foo) --> I like you
To capitalize every word you can use a (rather obscure) frontier pattern, like this:
foo = string.gsub ("i like you", "%f[%a].", string.upper)
print (foo) --> I Like You
In both cases I am using a regular expression to find what we want to capitalize. Then we pass down the standard function string.upper to string.gsub, and that turns the matching text into upper case. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Lxhd
(27 posts) Bio
|
Date
| Reply #2 on Tue 02 Feb 2016 05:18 AM (UTC) |
Message
| |
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
10,806 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top