Solved Change Paragraph All Upper Case To Sentence Case In Vbscript

June 14, 2020 at 03:09:55
Specs: Windows 7, 2.2/ 4gb
Despite searching the net and this forum I have been unable to find a vbscript to convert a paragraph with all letters in uppercase to sentence case. I would be grateful if anyone could provide a vbscript which could do this or give me a URL discussing the same. Thank you.

See More: Change Paragraph All Upper Case To Sentence Case In Vbscript

Reply ↓  Report •

✔ Best Answer
June 15, 2020 at 08:44:43

New vbscript to test :

Option Explicit
Dim inputText,Sentence,S
'A sentence is a series of characters, starting with at lease one whitespace character, that ends in one of ., ! or ?
inputText = "despite searching the net and this forum."&_
"i have been unable to find a vbscript to convert a paragraph with all letters in uppercase to sentence case."&_
"i would be grateful if anyone could provide a vbscript which could do this or give me a URL discussing the same.thank you !"

wscript.echo inputText

For each Sentence in Extracting_Sentences(inputText)
	S = S & Sentence & vbcrlf
Next

wscript.echo S
'------------------------------------------------------------------------------------
Function Extracting_Sentences(Data)
	Dim regEx,Match,Matches,Array_Sentences
	Set regEx = New RegExp
	regEx.Pattern = "[\S+\s+][^.!?]*[.!?]"
	regEx.IgnoreCase = True
	regEx.Global = True
	regEx.MultiLine = True
	Set Matches = regEx.Execute(Data)
	Array_Sentences = Array()
	For Each Match in Matches
		ReDim Preserve Array_Sentences(UBound(Array_Sentences) + 1)
		Array_Sentences(UBound(Array_Sentences)) = UpFirstLetter(Trim(Match.Value))
	Next
	Extracting_Sentences = Array_Sentences
End Function
'-----------------------------------------------------------------------------------
Function UpFirstLetter(s)
	UpFirstLetter = UCase(Left(s,1)) &  Mid(s,2)
End Function
'----------------------------------------------------------------------------------



#1
June 14, 2020 at 04:04:39
https://www.computing.net/answers/p...

This could be of some help


Reply ↓  Report •

#2
June 14, 2020 at 06:00:01
Thank you for replying but that reference you gave me seems to be all about duplication. There's nothing about conversion to sentence case. Sometimes the terms proper, title and sentence case are often loosely used. What I am looking for is the conversion of the first letter of the first word in each sentence to uppercase with the rest of the sentence text in lowercase.

Reply ↓  Report •

#3
June 14, 2020 at 11:46:30
Just give a try for this vbscript :

UP1Letter_Word.vbs

str = "what i am looking for is the conversion of the first letter of the first word in each sentence to uppercase with the rest of the sentence text in lowercase."

wscript.echo "Before conversion :" & vbcrlf &_
str & vbcrlf & vbcrlf &_
"After Conversion :" & vbcrlf &_
UpFirstLetter(str)

'-----------------------------------------------------------------------------------------
Function UpFirstLetter(str)
	ArrStr = Split(str,chr(32))
	For i=LBound(ArrStr) To UBound(ArrStr)
		O = O & Ucase(Left(ArrStr(i),1)) & LCase(Right(ArrStr(i),Len(ArrStr(i))-1)) & chr(32) 
	Next
	UpFirstLetter = Trim(O)
End Function
'-----------------------------------------------------------------------------------------

message edited by Hackoo


Reply ↓  Report •

Related Solutions

#4
June 15, 2020 at 02:18:28
Hi, Hakoo, thank you for your quick response. Unfortunately your script has carried out a conversion to "Title Case" not "Sentence Case". For the difference see https://en.wikipedia.org/wiki/Lette... As the paragraph will have more than one sentence in it will your script cope with that? Pardon my assumption that you'll amend your script for me!

Thank you


Reply ↓  Report •

#5
June 15, 2020 at 08:44:43
✔ Best Answer

New vbscript to test :

Option Explicit
Dim inputText,Sentence,S
'A sentence is a series of characters, starting with at lease one whitespace character, that ends in one of ., ! or ?
inputText = "despite searching the net and this forum."&_
"i have been unable to find a vbscript to convert a paragraph with all letters in uppercase to sentence case."&_
"i would be grateful if anyone could provide a vbscript which could do this or give me a URL discussing the same.thank you !"

wscript.echo inputText

For each Sentence in Extracting_Sentences(inputText)
	S = S & Sentence & vbcrlf
Next

wscript.echo S
'------------------------------------------------------------------------------------
Function Extracting_Sentences(Data)
	Dim regEx,Match,Matches,Array_Sentences
	Set regEx = New RegExp
	regEx.Pattern = "[\S+\s+][^.!?]*[.!?]"
	regEx.IgnoreCase = True
	regEx.Global = True
	regEx.MultiLine = True
	Set Matches = regEx.Execute(Data)
	Array_Sentences = Array()
	For Each Match in Matches
		ReDim Preserve Array_Sentences(UBound(Array_Sentences) + 1)
		Array_Sentences(UBound(Array_Sentences)) = UpFirstLetter(Trim(Match.Value))
	Next
	Extracting_Sentences = Array_Sentences
End Function
'-----------------------------------------------------------------------------------
Function UpFirstLetter(s)
	UpFirstLetter = UCase(Left(s,1)) &  Mid(s,2)
End Function
'----------------------------------------------------------------------------------


Reply ↓  Report •

#6
June 15, 2020 at 13:35:48
Hackoo, very many thanks for your script and your prompt response. The script does what I need.

Thank you again


Reply ↓  Report •

Ask Question