Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalizing first letter of strings

Tags:

excel

vba

I am trying to capitalize the first letter string sent in the array arr. The part of the code that does not work is the Right function, which causes the code to return an error. What could be the fix?

For Each sent In arr
    sent = UCase(Left(sent, 1)) & Right(sent, Len(sent) - 1)
    arr(i) = sent
    i = i + 1
Next
like image 414
brietsparks Avatar asked Dec 27 '14 16:12

brietsparks


People also ask

How do you capitalize the first letter of a string?

To capitalize the first character of a string, We can use the charAt() to separate the first character and then use the toUpperCase() function to capitalize it. Now, we would get the remaining characters of the string using the slice() function.

Which method is used to capitalize first letter of each word in a string?

In JavaScript, we have a method called toUpperCase() , which we can call on strings, or words. As we can imply from the name, you call it on a string/word, and it is going to return the same thing but as an uppercase.

Should string be capitalized?

The String type is capitalized because it is a class, like Object , not a primitive type like boolean or int (the other types you probably ran across).

How do you capitalize the first letter of a string in Python?

The first letter of a string can be capitalized using the capitalize() function. This method returns a string with the first letter capitalized. If you are looking to capitalize the first letter of the entire string the title() function should be used.


1 Answers

You can just use the StrConv() function for this. e.g. :

For i = LBound(arr) To UBound(arr)
   sent = arr(i)
   arr(i) = StrConv(sent, vbProperCase)
Next

or without a loop:

arr = Split(StrConv(Join$(arr, " "), vbProperCase), " ")
like image 130
SierraOscar Avatar answered Oct 15 '22 11:10

SierraOscar