Re:Capitalize String
Well, here is how I would do it. Note that this is Pascal version 7.0. I
am not sure if it will work in 5.5 or not. Also, it seemed to work on
the file I used, but I cannot guarentee it will work with yours.
---------- [program starts here] ----------
Program Cap;
Const
InF = 'in.txt'; {Change this to the file you want to read from.}
OutF = 'out.txt'; {Change this to the file you want to write to.}
Var
InFile, OutFile : Text;
Line : String[255];
Ct : Integer;
Begin
Assign(InFile,InF);
Reset(InFile);
Assign(OutFile,OutF);
ReWrite(OutFile);
Repeat
Readln(InFile,Line); {Reads entire line from the file.}
{Change to uppercase if first letter is lowercase.}
If Line[1] In ['a'..'z'] Then
Line[1] := Chr(Ord(Line[1]) - 32);
{Make every single letter lowercase for ease of programming.}
For Ct := 2 To Length(Line) Do
If Line[Ct] In ['A'..'Z'] Then
Line[Ct] := Chr(Ord(Line[Ct]) + 32);
{Note that this will make every character that has a space
before it uppercase. In this program, that is how a word
will be distinguished.}
{If the character is a letter and the char before is a space,
then make the character uppercase.}
For Ct := 2 To Length(Line) Do
If (Line[Ct] In ['a'..'z']) And (Line[Ct-1] = ' ') Then
Line[Ct] := Chr(Ord(Line[Ct]) - 32);
Writeln(OutFile,Line); {Write newly formatted line to file.}
Until (Eof(InFile)); {Stop when we have reached end of file.}
Close(OutFile);
Close(InFile); {Close each file when done.}
Writeln ('Done');
Readln;
End. {End program.}
---------- [program ends here] ----------
--
Ken Robbins
puyrebel <AT> prodigy <DOT> net
"If everything seems to be going well, you have obviously overlooked
something."
-- Murphy's Eighth Law
[snip]