How can i display the number of letters in a user supplied string?

2 ビュー (過去 30 日間)
Justin
Justin 2013 年 4 月 9 日
First_name=input('What is your first name? ','s');
User must input their name, and then how can i make matlab display the number of letters in their name?

回答 (3 件)

Image Analyst
Image Analyst 2013 年 4 月 9 日
Hint for your homework: use the length() function.

Yao Li
Yao Li 2013 年 4 月 9 日
編集済み: Yao Li 2013 年 4 月 9 日
fprintf('%d\n',length(First_name))
  2 件のコメント
Image Analyst
Image Analyst 2013 年 4 月 9 日
Normally we give them hints for homework and not the complete answer.
Yao Li
Yao Li 2013 年 4 月 9 日
Sorry, I don't know it is a homework. ^_^

サインインしてコメントする。


Walter Roberson
Walter Roberson 2013 年 4 月 9 日
編集済み: Walter Roberson 2013 年 4 月 9 日
How do you define "letters" for this purpose? Is space a "letter" ? Is dash a "letter"? If the user answers
Justin Porter the 3rd
then is the "3" a letter, or should your algorithm convert "the 3rd" to "III" ?
In some languages such as Swedish, there are representations as ä which is a true letter (not an accent on a letter) -- and yet it is considered acceptable (if not the best) to write ä as ae if necessary. Is ä one letter or two? If it is one letter and the ae form is encountered, then should it be considered as only one letter even though it takes two characters?
There are some languages in which there is a mix, with some letters that appear to be roman characters with accents (but are considered different characters, like the Swedish ä), and other letters that are roman characters with accents (and not considered distinct letters). How will your code handle those languages?
How many letters are there in
賈斯汀門房
?
  2 件のコメント
Yao Li
Yao Li 2013 年 4 月 9 日
Wow, Chinese!
a='賈斯汀門房'; length(a)
ans =
5
I'm a Chinese. The result 5 is right.
Also,you may use ASCII for selection.
Walter Roberson
Walter Roberson 2013 年 4 月 9 日
5 is not right. Chinese does not use letters, so the result for the number of letters has to be either 0 (no letters) or the number of letters in the translation to a language that does use letters.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by