473,226 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

Capitalise all words in a string

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
7 6798
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
"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
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
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
> 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

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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Nige | last post by:
Repost - as some readers took got sidetracked. To save me re-inventing the wheel, does anyone have a function to capitalise each word in form data? I was thinking along the lines of capitalise...
8
by: Rick | last post by:
I have a program that reads from a file. In the file are a series of words. I read in all the words into a string array, find the average length, count the number of words, display the longest...
5
by: derrick | last post by:
I used to program text RPG's in C back in high school, but I was very crude at it and only learned what I needed to get the job done. I am now about to graduate college with a degree in English and...
7
by: Sling | last post by:
I code in Rexx on the mainframe which has 2 built-in functions: word(s,i) & words(s). word(s,i) returns the ith word in the s(tring), and words(s) returns the number of words within the s(tring)....
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
7
by: abraxas | last post by:
Ok maybe someone here can help me. I have been learning c++ and have been toying with some basic programming and have run into something that I would have assumed would have been fairly easy. I...
20
by: dmurray14 | last post by:
Hey guys, I'm a C++ newbie here - I've messed with VB, but I mostly stick to web languages, so I find C++ to be very confusing at times. Basically, I am trying to import a text file, but I want...
6
by: Xernoth | last post by:
Hi, I have an exercise that requests the following: Write a function that reads words from an input stream and stores them in a vector. Use that function both to write programs that count the...
6
by: shapper | last post by:
Hello, I have a string and I need to get as many words possible counting from the beginning but without exceeding 120 characters. I can't break words and I the string shouldn't end with a...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.