By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Capitalise all words in a string

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
John Aspinall wrote:
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
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #2

P: n/a
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote:
John Aspinall wrote:
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?


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))

--
Tim Slattery
MS MVP(DTS)
Sl********@bls.gov
Jul 22 '05 #3

P: n/a
http://www.aspfaq.com/2299

--
http://www.aspfaq.com/
(Reverse address to reply.)


"John Aspinall" <jo***********@yahoo.co.uk> wrote in message
news:24**************************@posting.google.c om...
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

Jul 22 '05 #4

P: n/a
Tim Slattery wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote:
John Aspinall wrote:
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?


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
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #5

P: n/a
> 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... :-)
Jul 22 '05 #6

P: n/a

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

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 22 '05 #7

P: n/a

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:OZ**************@TK2MSFTNGP10.phx.gbl...
Tim Slattery wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote:
John Aspinall wrote:
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?


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 <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.
Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.