This question has already been answered:

Given a string that contains no more than 60 English letters, numbers, punctuation marks, which form words separated by a single space. Answer the question how many words.

Reported as a duplicate by members katso , Kromster , Nicolas Chabanovsky Nov 9 '16 at 5:38 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • string.split(" ").length; - etki
  • @Etki if there is no space between the punctuation mark and the words, then it will crookedly count (: - Suvitruf
  • @Suvitruf complex tasks let them solve without me - etki
  • Numbers are counted as a word or not? In the line "I'm 30 years old" - is it 2 words or 3? - Suvitruf
  • Duplicate.stackoverflow.com/questions/107220/… - Visman am

1 answer 1

 string[] count = "ДАНА СТРОКА".Split.(" ") 

count.Length this will be the number of words.

  • It also says: "letters, numbers, punctuation." Your example is valid only for your string - eastwing
  • How many words will be in the line "- Доктор,я не ставлю пробелы после запятых,вы мне поможете?\n- Нет! Только эвтаназия!" , if you divide it by spaces? Will every result be a word from the point of view of a person? - eastwing
  • So you can then also apply split to a comma. You can use a regular expression. You have the same question that says "which form words separated by a single space." It does not say that words can be separated by punctuation marks. - Ivan