Question: I am new to C# and only know the basics. I'm looking for a code example on how I would get every other word from a string variable. For example if the variable was

```
String x = "Help me, coding is difficult"; 

```

I would want to return single string "Help coding difficult". It needs to be a function that takes one string and return filtered version of it.

Someone suggested duplicates that I mostly already seen during my research:

* [How to split text into words?](https://stackoverflow.com/questions/16725848/how-to-split-text-into-words) shows very complicated logic that takes into account punctuation for example. I think I'm fine just to rely on spaces, but if you have better suggestion with an explanation - would be nice.
* [Select every second element from array using lambda](https://stackoverflow.com/questions/13082913/select-every-second-element-from-array-using-lambda) - seems promising, but sample shows how to work with integer array. I have string (or maybe string array if one can adapt string splitting code to provide one).
* [C# Print list of string array](https://stackoverflow.com/questions/42112051/c-sharp-print-list-of-string-array) that also sounds promising but it shows how to *print* the result, not how to return it as value from a function.

Answer: 
You need to define first what are word delimiters, just a space, a comma, period or semicolon or what else? Then you can use [`String.Split`](https://learn.microsoft.com/en-us/dotnet/api/system.string.split?view=net-6.0).

```
char[] wordDelimiter = new[] { ' ','\t', ',', '.', '!', '?', ';', ':', '/', '\\', '[', ']', '(', ')', '<', '>', '@', '"', '\'' };
String x = "Help me, coding is difficult"; 
string[] words = x.Split(wordDelimiter, StringSplitOptions.RemoveEmptyEntries);

```

Now you have an array with all words. But you want every other, you could fill them into a [`List<string>`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1?view=net-6.0) and use a [`for-loop`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/iteration-statements#the-for-statement) that skips every other:

```
var everyOtherWord = new List<string>();
for(int i = 0; i < words.Length; i += 2)
{
    everyOtherWord.Add(words[i]);
}

```

> 
> I would want to return "Help coding difficult"
> 
> 
> 

So you really want to have a `string` as result that contains these words separated by space? Then use [`String.Join`](https://learn.microsoft.com/en-us/dotnet/api/system.string.join?view=net-6.0) (somehow the *counterpart* method of `String.Split`):

```
string result = string.Join(" ", everyOtherWord);

```
```
string s = "You win some. You lose some.";

string[] subs = s.Split(' ');

for(int i=0 ; i < subs.length ; i+=2)
{
    Console.WriteLine($"Substring: {sub[i]}");
}

```