1. Another function
- Posted by Mike <michael at IGRIN.CO.NZ>
Oct 15, 1998
-
Last edited Oct 16, 1998
Alas, I too was bitten by the snake.exe..
Here is a function I had ready to post over a week ago.
It converts a simple character string into 'proper' format, ie the first
letter of a word is capitalised and the rest are lowercase. I have tried to
make it really fast, because that's what we all want, eh?
function proper(sequence s) -- "this is.a tEST" ==> "This Is.A Test"
integer b,c,d
d='a'-'A' -- this is the displacement between upper & lower case in
ascii
b=length(s)
if b then
if b>1 then
c=s[1]
for i=2 to b do
b=c
c=s[i]
if find(b,{' ','.',','}) then -- OK, make initial char upper
if c>='a' then
if c<='z' then
s[i]=c-d
end if
end if
elsif c<='Z' then -- otherwise make char lower
if c>='A' then
s[i]=c+d
end if
end if
end for
end if
c=s[1] -- now do first character for length 1 seq. or greater
if c>='a' then
if c<='z' then
s[1]=c-d
end if
end if
end if
return s
end function
sequence a a=",it, ,h i s.is atE.S.T"
puts(1,a&"\n")
a=proper(a)
puts(1,a)
Yours truly
Michael Palffy
michael at igrin.co.nz