String list manipulation
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
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?
list-manipulation
add a comment |Â
up vote
2
down vote
favorite
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?
list-manipulation
1
It is not clear what do you mean by 'string list', there are no strings inwords
. Also, have you tried searching documentation for string related functions that could help you?
â Kubaâ¦
Aug 21 at 5:24
Strings go between"
quotes in Mathematica.
â Szabolcs
Aug 21 at 7:31
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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?
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?
list-manipulation
list-manipulation
asked Aug 21 at 4:49
Hadi Sobhani
1286
1286
1
It is not clear what do you mean by 'string list', there are no strings inwords
. Also, have you tried searching documentation for string related functions that could help you?
â Kubaâ¦
Aug 21 at 5:24
Strings go between"
quotes in Mathematica.
â Szabolcs
Aug 21 at 7:31
add a comment |Â
1
It is not clear what do you mean by 'string list', there are no strings inwords
. Also, have you tried searching documentation for string related functions that could help you?
â Kubaâ¦
Aug 21 at 5:24
Strings go between"
quotes in Mathematica.
â Szabolcs
Aug 21 at 7:31
1
1
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
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
Strings go between
"
quotes in Mathematica.â Szabolcs
Aug 21 at 7:31
Strings go between
"
quotes in Mathematica.â Szabolcs
Aug 21 at 7:31
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
If the input and the desired output are lists of String
s:
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[strings, WordBoundary ~~ a_ :> ToUpperCase[a]]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
If the input and desired output are lists of Symbol
s:
words = cut, was, saw, clear, sharp, keen, tree, these;
Symbol /@ GeneralUtilities`ToTitleCase[ToString /@ words]
Cut, Was, Saw, Clear, Sharp, Keen, Tree, These
add a comment |Â
up vote
7
down vote
Could also use Capitalize
:
Capitalize["cut", "was", "saw", "clear", "sharp", "keen", "tree", "these"]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
If the input and the desired output are lists of String
s:
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[strings, WordBoundary ~~ a_ :> ToUpperCase[a]]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
If the input and desired output are lists of Symbol
s:
words = cut, was, saw, clear, sharp, keen, tree, these;
Symbol /@ GeneralUtilities`ToTitleCase[ToString /@ words]
Cut, Was, Saw, Clear, Sharp, Keen, Tree, These
add a comment |Â
up vote
3
down vote
accepted
If the input and the desired output are lists of String
s:
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[strings, WordBoundary ~~ a_ :> ToUpperCase[a]]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
If the input and desired output are lists of Symbol
s:
words = cut, was, saw, clear, sharp, keen, tree, these;
Symbol /@ GeneralUtilities`ToTitleCase[ToString /@ words]
Cut, Was, Saw, Clear, Sharp, Keen, Tree, These
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
If the input and the desired output are lists of String
s:
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[strings, WordBoundary ~~ a_ :> ToUpperCase[a]]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
If the input and desired output are lists of Symbol
s:
words = cut, was, saw, clear, sharp, keen, tree, these;
Symbol /@ GeneralUtilities`ToTitleCase[ToString /@ words]
Cut, Was, Saw, Clear, Sharp, Keen, Tree, These
If the input and the desired output are lists of String
s:
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[strings, WordBoundary ~~ a_ :> ToUpperCase[a]]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
If the input and desired output are lists of Symbol
s:
words = cut, was, saw, clear, sharp, keen, tree, these;
Symbol /@ GeneralUtilities`ToTitleCase[ToString /@ words]
Cut, Was, Saw, Clear, Sharp, Keen, Tree, These
edited Aug 21 at 5:41
answered Aug 21 at 5:12
kglr
161k8185384
161k8185384
add a comment |Â
add a comment |Â
up vote
7
down vote
Could also use Capitalize
:
Capitalize["cut", "was", "saw", "clear", "sharp", "keen", "tree", "these"]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
add a comment |Â
up vote
7
down vote
Could also use Capitalize
:
Capitalize["cut", "was", "saw", "clear", "sharp", "keen", "tree", "these"]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
add a comment |Â
up vote
7
down vote
up vote
7
down vote
Could also use Capitalize
:
Capitalize["cut", "was", "saw", "clear", "sharp", "keen", "tree", "these"]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
Could also use Capitalize
:
Capitalize["cut", "was", "saw", "clear", "sharp", "keen", "tree", "these"]
"Cut", "Was", "Saw", "Clear", "Sharp", "Keen", "Tree", "These"
answered Aug 21 at 5:54
Carl Woll
57.8k273150
57.8k273150
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f180335%2fstring-list-manipulation%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
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
Strings go between
"
quotes in Mathematica.â Szabolcs
Aug 21 at 7:31