Jump to content
UBot Underground

[SOLUTION] - Function to change first character in string to Uppercase


Recommended Posts

Hi Guys,

 

I couldn't find a UBot command to do this so I wrote a quick function (uses Regex). The one included with UBot changes each word in the string to uppercase whereas this changes just the first letter of a string (sentence).

 

define $ucFirst(#pString) {
    return($replace regular expression(#pString"^[\\s\\S]\{0,1\}"$change text casing($substring(#pString, 0, 1), "Upper Case")))
}

Link to post
Share on other sites

That function changes all the words first letters to uppercase. The function I did above does the first character of the sentence / string (not each word). If that makes sense.

 

'this string becomes' - 'This String Becomes' - UBot Function

'this string becomes' - 'This string becomes' - My function above.

Link to post
Share on other sites

You could also do that without regex:

define $ucFirst(#pString) {
    return("{$change text casing($substring(#pString, 0, 1), "Upper Case")}{$substring(#pString, 1, $subtract($text length(#pString), 1))}")
}

  • Like 1
Link to post
Share on other sites

 

You could also do that without regex:

define $ucFirst(#pString) {
    return("{$change text casing($substring(#pString, 0, 1), "Upper Case")}{$substring(#pString, 1, $subtract($text length(#pString), 1))}")
}

 

You are right :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...