473,657 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6811
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******@NOyah oo.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.goo gle.com...
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******@NOyah oo.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******@NOyah oo.SPAMcom> wrote in message
news:OZ******** ******@TK2MSFTN GP10.phx.gbl...
Tim Slattery wrote:
"Bob Barrows [MVP]" <re******@NOyah oo.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
3214
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 the first letter of the string, then any other letter after a space or hyphen. So many users seem to think that just because they are online they can use addresses like "8 brown road, chatham, kent" and so I have to manually change them.
8
2190
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 word and how long it is, and display the smallest word and how long it is. All that is working fine, but what I need to do it format certain words that contain a period at the end of them (ex: a word at the end of a sentence), words with quotes...
5
3123
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 have had an interest in the structure of language. In order to begin with my little program, I need to be able to take a string like "The dog jumped." and be able to take the first word from the sentence and assign it to a string, such as word1,...
7
43592
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). Is there something equivalent in C#, preferably built-in (assumed better performance), or sample code? Thanks in advance.
9
5259
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 w1 and w2 make up the first string and, w3 and w4 make up the second string. I do not want to allocate memory, then put the words together to create a string only to facilitate strcmp() comparison. My question; Does anyone know how to get the...
7
9340
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 am wanting to input a list of words into the program and I thought you would use and array to do that, but I am not having any luck finding info on storing an actual list of words. I have set it up so that it prompts you for the number of words. ...
20
5128
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 to do it word by word. I am confused as to how to do this. Typically, I would think it would make sense to try and input the words into strings, but for this application I need to use character arrays and pointers. So what's the best way to go...
6
3939
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 number of words in the input, and to count how many times each word occurred.
6
2924
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 comma, a dot, ... How can I do this? Thank You, Miguel
0
8399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.