1

I am trying to get each sentence from my rtextbox into an array. However, when I use .split method, it gives me empty spaces as part of the array.

How can I either remove the empty ones or not have them come into the array in the first place?

Dim senArray() = RTextBox.Text.Split(New String() {"."}, StringSplitOptions.RemoveEmptyEntries)

Thank you!

4
  • Can you give an example of the output? Do you have actual entries that are blank, or do you have spaces at the the start of some sentences? Commented Nov 7, 2014 at 15:47
  • when i try linq Where expression, it gives me the following error: Variable cannot be initialized with non-array type 'System.Collections.Generic.IEnumerable(Of String)' Commented Nov 7, 2014 at 15:49
  • 2
    try adding .ToArray() after your Where expression Commented Nov 7, 2014 at 15:50
  • @valverij Missed that when I added my answer - Thanks! Commented Nov 7, 2014 at 16:08

1 Answer 1

9

You can use a linq Where expression to remove the whitespace entries:

Dim senArray() = RTextBox.Text.Split(
                     New String() {"."}, StringSplitOptions.RemoveEmptyEntries
                 ).Where(
                     Function(s) Not String.IsNullOrWhitespace(s)
                 ).ToArray()
Sign up to request clarification or add additional context in comments.

2 Comments

Where is not a member of System.array :(
@johnktejik Indeed - it's an extension method made available via System.Linq - you'd need to include that using to make it available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.