Capitalise all words in a string

J

John Aspinall

Hi,

Can someone please tell me how to capitalise all words in a string
that are seperated by spaces. The string is variable and not the same
every time hence I cant use the Ucase function as I wont know the
exact position of the start of each word.

Cheers....John
 
B

Bob Barrows [MVP]

John said:
Hi,

Can someone please tell me how to capitalise all words in a string
that are seperated by spaces. The string is variable and not the same
every time hence I cant use the Ucase function as I wont know the
exact position of the start of each word.

Cheers....John

? Why won't UCase work? Please provide an example string, and SHOW the
result you wish to obtain. Do you wish to do proper casing (capitalize only
the first letter of each word)?

Bob Barrows
 
T

Tim Slattery

Bob Barrows said:
? Why won't UCase work?

Because OP wants the first letter of each word uppercase, the rest
lowercase. Something like this might do it in VBScript (this is not
tested!!):

's1 is a string containing blank-separated words.
'The first letter of each word is to be capitalized
set re = new RegExp
re.pattern = " [a-z]"
re.global = "true"
re.replace(s1, ucase($1))
 
B

Bob Barrows [MVP]

Tim said:
Because OP wants the first letter of each word uppercase, the rest
lowercase.

Where do you see that in his post? Why do you leap from "capitalise all
words " to "first letter of each word uppercase"? He could just as easily
have wanted something like this:

abcd efg hijkl mn op

to become this:

abcd EFG hijkl MN op

Or something equally bizarre.

I congratulate you for going to the trouble of writing that code based on a
guess about what the OP wanted. I hope your guess was correct so your time
was not wasted
 
A

Aaron [SQL Server MVP]

I hope your guess was correct so your time
was not wasted

Exactly why I post links to existing code instead of writing it over and
over again. :)

After all, if it's not what they wanted (and even sometimes when it is),
I'll hear about it... :)
 
J

John Aspinall

Sorry, I explained this poorly. Yes I did want just the first letter of
each word capitalised and Im using VBScript.

Thanks.
 
O

Over-rider

Bob Barrows said:
Where do you see that in his post? Why do you leap from "capitalise all
words " to "first letter of each word uppercase"? He could just as easily
have wanted something like <snip>


It is an easy and fair deduction to make from the OP: "I can't use the
Ucase function as I wont know the exact position of the start of each word"
can only mean that he wants to capitalize the start of each word.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,163
Messages
2,570,897
Members
47,434
Latest member
TobiasLoan

Latest Threads

Top