I am trying to split at every space ” “, but it will not let me remove empty entries and then find the length, but it is treated as a syntax error.
My code:
TextBox1.Text.Split(" ", StringSplitOptions.RemoveEmptyEntries).Length
What am I doing wrong?
Well, the first parameter to the
Splitfunction needs to be an array of strings or characters. Try:You might not have noticed this before when you didn’t specify the 2nd parameter. This is because the
Splitmethod has an overload which takes in a ParamArray. This means that calls toSplit("string 1", "string 2", "etc")auto-magically get converted into a call toSplit(New String() {"string 1", "string 2", "etc"})