String list manipulation

String list manipulation



I have a string list including some words. For example, I have


words=cut, was, saw, clear, sharp, keen, tree, these;



I want to write a code that changes the first letter of each word to the capital letter. I mean I want to have the result as


Cut, Was, Saw, Clear, Sharp, Keen, Tree, These;



How can I figure it out?





It is not clear what do you mean by 'string list', there are no strings in words. Also, have you tried searching documentation for string related functions that could help you?
– Kuba
Aug 21 at 5:24



words





Strings go between " quotes in Mathematica.
– Szabolcs
Aug 21 at 7:31


"




2 Answers
2



If the input and the desired output are lists of Strings:


String


strings = "cut", "was", "saw", "clear", "sharp", "keen", "tree", "these";

GeneralUtilities`ToTitleCase[strings]



"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"



Alternatively, you can use StringReplace:


StringReplace


StringReplace[strings, WordBoundary ~~ a_ :> ToUpperCase[a]]



"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"



If the input and desired output are lists of Symbols:


Symbol


words = cut, was, saw, clear, sharp, keen, tree, these;

Symbol /@ GeneralUtilities`ToTitleCase[ToString /@ words]



Cut, Was, Saw, Clear, Sharp, Keen, Tree, These



Could also use Capitalize:


Capitalize


Capitalize["cut", "was", "saw", "clear", "sharp", "keen", "tree", "these"]



"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)