How to find words in a string which are greater than given length with C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

public class Program
{
	public static void Main(string[] args)
	{
		string str = "C# is a general purpose high level programming language";
        int length = 6;

		string[] array = str.Split(' ');
		List<string> list = new List<string>();

		foreach (string s in array) {
			if (s.Length > length) {
				list.Add(s);
			}
		}

		Console.WriteLine(String.Join(", ", list)); 
	}
}



/*
run:
  
general, purpose, programming, language
  
*/


 



answered Nov 28, 2023 by avibootz
...