Page 1 of 1 1
Topic Options
#120552 - 2004-06-03 03:14 PM How to print with an initial capital
Gos Offline
Fresh Scripter

Registered: 2004-05-28
Posts: 23
I need a string to have inital capitals.

For those who do not understand my problem, this is what I need:

I need this string: "blautkak marsipan" to be written like this: "Blautkak Marsipan". The string is variable, so I can not write it manually.

-Gos-

Top
#120553 - 2004-06-03 03:36 PM Re: How to print with an initial capital
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Code:
break on


$string = "blueboy martian"

$string = split($string)

for $i = 0 to ubound($string)
$string[$i] = ucase(left($string[$i],1)) + substr($string[$i],2)
next

$string = join($string)

? $string

get $

exit 1




there must be a better way though
_________________________



Top
#120554 - 2004-06-03 03:40 PM Re: How to print with an initial capital
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
be careful ...

this capitalizes every single word in the given string, no matter how long it is
_________________________



Top
#120555 - 2004-06-03 03:47 PM Re: How to print with an initial capital
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I'd do Ucase(left(...)) + Lcase(substr(...))
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#120556 - 2004-06-03 03:50 PM Re: How to print with an initial capital
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Give this a try...

Code:

Break On

fnProper("hello chris")


Function fnProper($String)
If Not VarType($String) = 8 Exit 1 EndIf
$String = Split($String)
Dim $Array[Ubound($String)], $Index
For Each $String in $String
$Array[$Index] = Ucase(Left($String,1)) + Right($String,Len($String)-1)
$Index = $Index + 1
Next
$fnProper = Join($Array)
EndFunction


Top
#120557 - 2004-06-03 03:51 PM Re: How to print with an initial capital
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
how about:
Code:

$string = "blueboy martian behevo"
for $c=0 to 25
$string = join(split($string,' '+chr(97+$c)),' '+chr(65+$c))
next
? $string
get $

_________________________
!

download KiXnet

Top
#120558 - 2004-06-03 04:28 PM Re: How to print with an initial capital
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I kinda like this one, as a "proper" Proper function will convert the first character or a word to uppercase and all other characters in the word to lowercase.

Code:

fnProper("hElLo ChRiS")


Function fnProper($String)
$String = Split($String)
For $i = 0 to Ubound($String)
$String[$i] = UCase(Left($String[$i],1)) + LCase(SubStr($String[$i],2))
Next
$fnProper = Join($String)
EndFunction


Top
#120559 - 2004-06-03 04:40 PM Re: How to print with an initial capital
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
neat,

but a proper "proper" Proper function would have it'S internal vars dimmed ($i)

By the way ... the only practical use for this that I can think of is correcting song titles for MP3 files as I think they used to be written capitalized, no?


Edited by Jochen (2004-06-03 04:43 PM)
_________________________



Top
#120560 - 2004-06-03 04:47 PM Re: How to print with an initial capital
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Dang, I meant to dim that var, but forgot.

I've used it in Excel to correct capitalization for proper names. It has its uses.

Top
#120561 - 2004-06-04 08:58 AM Re: How to print with an initial capital
Gos Offline
Fresh Scripter

Registered: 2004-05-28
Posts: 23
Thank you guys. Your examples works. =)

-Gos-

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.032 seconds in which 0.012 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org