Capitalizing the first character/letter in a word
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 9
- Joined: Wed Feb 16, 2011 5:32 pm
Capitalizing the first character/letter in a word
What's the easiest most direct way to change only the first character in a word to uppercase, leaving the rest to lower case?
Thanks in advance...
Thanks in advance...
Re: Capitalizing the first character/letter in a word
Code: Select all
put toUpper(char 1 of word 1 of field "test") into char 1 of word 1 of field "test"
toUpper
word
wordoffset
note that words are not what you'd assume them to be in LiveCode, so depending on the input text, you'd need to adapt.
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Re: Capitalizing the first character/letter in a word
This is called Titletext. But do you need the first char of each word, or the first char of each sentence?
The first is easy. If the second, there was a thread a while back that gave several
solutions and opinions. It took careful parsing, watching out for periods, decimal points, etc. Check the archives.
Bjornke, what did you mean when you said words are not what you assume them to be?
Craig Newman
The first is easy. If the second, there was a thread a while back that gave several
solutions and opinions. It took careful parsing, watching out for periods, decimal points, etc. Check the archives.
Bjornke, what did you mean when you said words are not what you assume them to be?
Craig Newman
Re: Capitalizing the first character/letter in a word
Check out the thread in this forum called "saving contents of entire stack".
Craig Newman
Craig Newman
Re: Capitalizing the first character/letter in a word
words in LC are either delimited by space, return or tab, or they're within quotes. the part about quotes does trip people up the first time. additionally, punctiation is ignored when considering words, so finding out where a sentence starts can be hard too.
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Re: Capitalizing the first character/letter in a word
Bjornke.
Oh, I see what you meant now. Yes, words are the most slippery of the chunks. Do you remember the long discussion about why "A B" (an "A", two spaces, and a "B") was two words and not three?
Craig
Oh, I see what you meant now. Yes, words are the most slippery of the chunks. Do you remember the long discussion about why "A B" (an "A", two spaces, and a "B") was two words and not three?
Craig
Re: Capitalizing the first character/letter in a word
Hi Barkandgargle,
I write a little function it make the job
Best regards
Jean-Marc
I write a little function it make the job
Code: Select all
on mouseUp
put fld "myFld" into mytext
put FirstCharHi(mytext)
end mouseUp
function FirstCharHi ptext
put numtochar(34) into tsearch -- 34 = chartonum of ",maeby you have others
put "•" into tNewChar
put replacetext(pText,tsearch,tNewChar) into LeT
repeat with i = 1 to the num of words of LeT
put word i of LeT into UnW
if char 1 of UnW = "•" then
put 2 into LeFirstChar
else
put 1 into LeFirstChar
end if
put char LeFirstChar of UnW into LeC
put chartonum(LeC) into LeCTN
if LeCTN > 96 and LeCTN <123 then
subtract 32 from LeCTN
put numtochar(LeCTN) into char LeFirstChar of word i of LeT
wait 1 milliseconds
end if
end repeat
put replacetext(LeT,tNewChar,tsearch) into LeT
return LeT
end FirstCharHi
Jean-Marc
https://alternatic.ch
-
- Posts: 9
- Joined: Wed Feb 16, 2011 5:32 pm
Re: Capitalizing the first character/letter in a word
Thanks for your help. The code above is what I thought should work, but I didn't have it exactly quite right. But this now works. Appreciate it.BvG wrote:Code: Select all
put toUpper(char 1 of word 1 of field "test") into char 1 of word 1 of field "test"