Jamie Taylor
Jamie Taylor

Reputation: 3530

Split string adding extra string when no data is there

I have some code that splits a session into strings by a -

My session looks something like this 123-456-789- and I split it like this

Dim MyString As String() = Session("MySession").Split("-"C)

And i've got a some code like this

Dim x as Integer

For x = 0 to MyString - 1

Response.write("Ref: " & MyString(x) & "<br>")

Next

This writes the code like this

Ref: 123
Ref: 456
Ref: 789
Ref:

So it's adding an extra Ref where it shouldn't be because there is no data after the last -

Is there a way to stop this adding in the extra one?

Thanks

Upvotes: 0

Views: 145

Answers (1)

iburlakov
iburlakov

Reputation: 4232

Use String.Split(String[], StringSplitOptions) method, with StringSplitOptions.RemoveEmptyEntries as second param.

Upvotes: 6

Related Questions