Convert name to proper case

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Pauls74462
Posts: 6
Joined: Sat Jul 15, 2006 2:47 pm

Convert name to proper case

Post by Pauls74462 » Wed Mar 02, 2011 11:43 pm

How to I convert a students name to proper case is they use all lower case?

Code: Select all

on mouseUp
   put  fld StudentsName into fld LabelSN
   put "" into fld StudentsName
   
   ( convert students name to Students Name)
   
end mouseUp


jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Convert name to proper case

Post by jmburnod » Thu Mar 03, 2011 12:05 am

Hi Pauls

You can use the upper function

Code: Select all

on mouseUp
   put UpperFirstChar("john steinbeck")
end mouseUp

function UpperFirstChar  pName
   put the num of words of pName into nbW
   repeat with i = 1 to nbw
      put upper(char 1 of word i of pName) into char 1 of word i of pName 
      wait 1milliseconds
   end repeat
   return pName
end UpperFirstChar
Best

Jean-Marc
https://alternatic.ch

Pauls74462
Posts: 6
Joined: Sat Jul 15, 2006 2:47 pm

Re: Convert name to proper case

Post by Pauls74462 » Thu Mar 03, 2011 12:19 am

jmburnod wrote:Hi Pauls

You can use the upper function

Code: Select all

on mouseUp
   put UpperFirstChar("john steinbeck")
end mouseUp

function UpperFirstChar  pName
   put the num of words of pName into nbW
   repeat with i = 1 to nbw
      put upper(char 1 of word i of pName) into char 1 of word i of pName 
      wait 1milliseconds
   end repeat
   return pName
end UpperFirstChar
Best

Jean-Marc
confused, is this what my code should look like?

Code: Select all


on mouseUp
   put  fld StudentsName into fld LabelSN
   put "" into fld StudentsName
   
   put UpperFirstChar("john steinbeck")
end mouseUp

function UpperFirstChar  pName
   put the num of words of pName into nbW
   repeat with i = 1 to nbw
      put upper(char 1 of word i of pName) into char 1 of word i of pName 
      wait 1milliseconds
   end repeat
   return pName
end UpperFirstChar


dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10318
Joined: Wed May 06, 2009 2:28 pm

Re: Convert name to proper case

Post by dunbarx » Thu Mar 03, 2011 5:31 am

A function takes a value and returns a result. A function can live anywhere; it is called as needed. They sort of work behind the scenes. Place it in the card or stack script and it will always be available.

It is then up to you to supply the data for the function to work with and and a destination to put it in. You could say:

answer upperFirstChar(yourText)

or:

put upperFirstChar(yourText) into field yourField

Try these in a button mouseUp handler. Supply the actual data in any way you like.

Write back if this is still not clear. Functions take just a little getting used to.

Craig Newman

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Convert name to proper case

Post by BvG » Thu Mar 03, 2011 2:44 pm

Uhm you really should not wait for 1 millisecond like that. If you fear that your repeat loop might block you should do something else. But with such a simple one that's almost impossible, even with tens of thousands of entries. To allow nonblocking repeat, use this line:

wait 0 seconds with messages
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10318
Joined: Wed May 06, 2009 2:28 pm

Re: Convert name to proper case

Post by dunbarx » Thu Mar 03, 2011 4:04 pm

I wasn't sure why there was a wait of any kind. Perhaps Jean-Marc just does this as a matter of course. The function will be instantaneous with all but huge amounts of data, and I don't think that is the case here.

But I agree that if one does, in general, unblock loops, the "wait with messages" form is the most robust.

Craig Newman

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Convert name to proper case

Post by BvG » Thu Mar 03, 2011 4:05 pm

The problem is, with "wait 1 millisecond" (no "with messages" at the end), one actually does not "rest" the processor, or give a break to the computer. all it does is slow the loop down noticeably :)
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Pauls74462
Posts: 6
Joined: Sat Jul 15, 2006 2:47 pm

Re: Convert name to proper case

Post by Pauls74462 » Thu Mar 03, 2011 6:59 pm

Pauls74462 wrote:
jmburnod wrote:Hi Pauls

You can use the upper function

Code: Select all

on mouseUp
   put UpperFirstChar("john steinbeck")
end mouseUp

function UpperFirstChar  pName
   put the num of words of pName into nbW
   repeat with i = 1 to nbw
      put upper(char 1 of word i of pName) into char 1 of word i of pName 
      wait 1milliseconds
   end repeat
   return pName
end UpperFirstChar
Best

Jean-Marc
confused, is this what my code should look like?

Code: Select all


on mouseUp
   put  fld StudentsName into fld LabelSN
   put "" into fld StudentsName
   
   put UpperFirstChar("john steinbeck")
end mouseUp

function UpperFirstChar  pName
   put the num of words of pName into nbW
   repeat with i = 1 to nbw
      put upper(char 1 of word i of pName) into char 1 of word i of pName 
      wait 1milliseconds
   end repeat
   return pName
end UpperFirstChar


This puts the name "john steinbeck" in proper case in a message box?

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Convert name to proper case

Post by Klaus » Thu Mar 03, 2011 7:15 pm

Hi Paul,
Pauls74462 wrote:This puts the name "john steinbeck" in proper case in a message box?
Yes, if you don't specify a target like "put tVariable into field xyz" the output will go into the message box!

Best

Klaus

Pauls74462
Posts: 6
Joined: Sat Jul 15, 2006 2:47 pm

Re: Convert name to proper case

Post by Pauls74462 » Sat Mar 05, 2011 8:32 pm

Klaus wrote:Hi Paul,
Pauls74462 wrote:This puts the name "john steinbeck" in proper case in a message box?
Yes, if you don't specify a target like "put tVariable into field xyz" the output will go into the message box!

Best

Klaus

Code: Select all

on mouseUp
   put  fld StudentsName into fld LabelSN
   put "" into fld StudentsName
   
   put UpperFirstChar("john steinbeck") <<< I want the name of the student here.
end mouseUp
How do I get the students first & last name to be caps ans put it in the field LableSN

The fld StudentsName is the text box where the student types his/her name in.

The fld LableSN is the label where the students name proper case goes.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Convert name to proper case

Post by jmburnod » Sat Mar 05, 2011 9:16 pm

Hi Paul,
If i understand what you want:

Code: Select all

on mouseUp
   put  fld "StudentsName" into tName
   put "" into fld "StudentsName"
   put UpperFirstChar(tName) into fld "LabelSN" --<<< I want the name of the student here.
end mouseUp
Best
Jean-Marc
https://alternatic.ch

Post Reply