i have method, which have parameter "word" returns Word first and the last letter with string. between first and last letter there is three points. example when you write "stackoverflow" it returns it like that "s...w"
I have this code but i wont work.
namespace stackoverflow
{
class Program
{
static void Main(string[] args)
{
string word = "stackoverflow";
string firsLast = FirsLast(word);
Console.WriteLine(firsLast);
Console.ReadKey();
}
private static string FirsLast(string word)
{
string firsLast = "...";
for (int i = 0; i < word.Length; i += 2)
{
firsLast += word.ElementAt(i);
}
return firsLast;
}
}
}
Why not
if (word.Length >= 2)
{
return word[0] + "..." + word[word.Length - 1];
}
if (word.Length >= 2)
{
return word.First() + "..." + word.Last();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With