473,382 Members | 1,464 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,382 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 6802
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.