main.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
// C# program to find all string // which are greater than given length k using System; class GFG { // function find string greater than // length k static void string_k(string s, int k) { // create the empty string string w = ""; // iterate the loop till every space for(int i = 0; i < s.Length; i++) { if(s[i] != ' ') // append this sub string in // string w w = w + s[i]; else { // if length of current sub // string w is greater than // k then print if(w.Length > k) Console.Write(w + " "); w = ""; } } } // Driver code static void Main() { string s = "geek for geeks"; int k = 3; s = s + " "; string_k(s, k); } } // This code is contributed by // Manish Shaw (manishshaw1) |