0

can anybody help me with this given assignment? "Write a function that takes as input the message (a string) and checks whether the number of characters is less than 160 or not. If the length of the message is less than 160, the message should be returned. If the length of the message is greater than 160, a string consisting of only the first 160 characters should be returned."

I am unsure how to design a program that prints a string consisting of only 160 letters if the amount of letters are above.

Yega
  • 3
  • 1
  • What programming language are you using? Just check the string.length and if it was above 160 then, get the substring(0,160) that's it. – RajeshKannan Oct 18 '14 at 09:36
  • "Can you do my assignment for me" type questions where you have shown no attempt to try the question yourself are frowned upon here. – Polynomial Oct 18 '14 at 09:45

1 Answers1

0

If the string contains more than 160 characters, loop from 1 to 160 (or 0 to 159 if your language is zero based), each time outputting the character at the position of the loop index. You can also use a substring function if your language has one.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278