Thursday, 24 November 2016

Count the length of last word in a String

Suppose you have a string "I love Programming"
Output - should be  11.
if there is no word then Output: 0

static void Main1(string[] args)
        {
            string s = Console.ReadLine();
            string[] arr = s.Split(' ');
            int length = arr.Length;
            Console.WriteLine(arr[length - 1].Length);
            Console.ReadLine();

        }

1 comment:

Note: only a member of this blog may post a comment.