Code archives/Algorithms/Capitalization

This code has been declared by its author to be Public Domain code.

Download source code

Capitalization by dna2013
The algorithm does exactly that.

Just pass your string and the function capitalizes the first letter of each word in the string.

I first wrote an algorithm that worked but which used Dim a(50) for counting the location of the spaces.
This worked but it limited the use of the routine.

The routine below works without the array and is one fifth the size.

I have not checked the limits of the routine. There may be one but it may not be necessary unless someone wants to use it on a large amount of information at once.

Like an Encyclopedia or something similar.

Enjoy
Function CFLOW$(W$)
	While Instr(W$," ")
		C$=Upper$(Left$(W$,1)):V$=V$+C$+Mid$(W$,2,Instr(W$," ")-1):W$=Mid$(W$,Instr(W$," ")+1)
	Wend
	V$=V$+Upper$(Left$(W$,1))+Mid$(W$,2)
	Return V$
End Function

Comments

BlitzSupport2013
Hi dna, you posted your explanation into the code box, so I've edited this entry a little -- you might want to just check I haven't messed up the function! BTW You don't need to use [code] tags inside the code box.


xlsior2013
Just for clarification: This function capitalizes the first letter of each word, not the entire string!

(dna: you may want to consider also looking for TAB in addition to spaces)


dna2013
Thanks for notifying me of it needing clarification.


Hardcoal2013
How do i post to code archive?


Code Archives Forum