Delete characters after a whitespace

I need to be able to delete characters after a whitespace in a string. This is so I can get the first part of a postal code. For example, I want to convert the psotcode NW3 4DD to just NW3 etc. Is there a way to do this with Regex or in vb.net?

Seb
sebastizAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=169&lngWId=10

postcode = yourdata.SubString(1, yourdata.IndexOf(" "))
0
 
SanclerCommented:
.Substring works with a zero-based, not a one-based index.  That should be

   postcode = yourdata.SubString(0, yourdata.IndexOf(" "))

Roger
0
 
sebastizAuthor Commented:
This is what Ive got, but doesnt seem to be working:

 dt.Columns("Regex Postcode").Expression = "substring(pcode, 0,4)"
pcode has ben defined in the SQL statement
0
 
sebastizAuthor Commented:
I sorted it- it is a 1 based index, not zero, which is where my error was.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.