How to find the largest word in a string with C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        string str = "C# is a general purpose multi paradigm programming language";
        string[] words = str.Split(new[] {" "}, StringSplitOptions.None);
        string word = "";
        int max_len = 0;
                        
        foreach (String s in words) {
            if (s.Length > max_len) {
                word = s;
                max_len = s.Length;
            }
        }
        Console.WriteLine(word);
    }
}



/*
run:
 
programming
 
*/

 



answered Sep 14, 2021 by avibootz

Related questions

1 answer 102 views
1 answer 140 views
1 answer 111 views
1 answer 128 views
1 answer 139 views
1 answer 121 views
...