Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capitalize first letter of a string in VBScript

Tags:

vbscript

I read a really helpful post here How do I make the first letter of a string uppercase in JavaScript? and I was curious of a good solution using VBScript.

like image 427
Daniel Avatar asked Dec 08 '22 17:12

Daniel


2 Answers

>> s = "first word of string"
>> WScript.Echo UCase(Left(s, 1)) &  Mid(s, 2)
>>
First word of string
like image 59
Ekkehard.Horner Avatar answered Feb 23 '23 21:02

Ekkehard.Horner


str = "mY nAME iS sACHIN"

arrStr = split(str," ")

For i=0 to ubound(arrStr)

 word = lcase(trim(arrStr(i)))
 word = replace(word,mid(word,1,1),chr(asc(mid(word,1,1))-32),1,1)
 str1 = str1 & word & " "
next

msgbox trim(str1)

Output: My Name Is Sachin

like image 40
Rishabh Avatar answered Feb 23 '23 19:02

Rishabh