Change 1st letter of every 'word' to upper case

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Hovik
Moderator
Moderator
Posts: 184
Joined: Tue Sep 11, 2007 8:58 am

Change 1st letter of every 'word' to upper case

#1

Postby Hovik » Wed Dec 05, 2007 5:21 pm

I want to capitalise 1st letter of every word in a field.
Specifically, I have a name field where parts of the name are separated by a space, or by a -(dash) for double barrelled names.
How can I change the 1st letter of every name, including the 2nd part of a double barrelled name, to upper case.
Is this possible in FPL?
0 x

Hovik
Moderator
Moderator
Posts: 184
Joined: Tue Sep 11, 2007 8:58 am

#2

Postby Hovik » Wed Dec 05, 2007 5:48 pm

A function, say initcap, would be nice. But there is no such function in FPL, as yet.
In the meantime, the following code will do the job.
Need a numeric field called POS. The field to be converted is called NAME.

Code: Select all

if &#91;length&#40;NAME&#41; < 2&#93;

   set NAME = uppercase&#40;NAME&#41;;

else

   set NAME = uppercase&#40;substring&#40;NAME,1,1&#41;&#41; + lowercase&#40;substring&#40;NAME,2,length&#40;NAME&#41;-1&#41;&#41;;

   set POS = 2;
   loop &#91;POS < length&#40;NAME&#41;&#93;
      if &#91;substring&#40;NAME,POS,1&#41; = ' ' or substring&#40;NAME,POS,1&#41; = '-' &#93;
         set POS = POS + 1;
         set NAME = substring&#40;NAME,1,POS - 1&#41; + uppercase&#40;substring&#40;NAME,POS,1&#41;&#41; + substring&#40;NAME,POS+1,length&#40;NAME&#41;-1&#41;;
      endif
      set POS = POS + 1;
   endloop

endif
0 x


Who is online

Users browsing this forum: No registered users and 15 guests