Solved

Delete characters after a whitespace

Posted on 2007-03-18
4
390 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:sebastiz
  • 2
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18743129
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=169&lngWId=10

postcode = yourdata.SubString(1, yourdata.IndexOf(" "))
0
 
LVL 34

Expert Comment

by:Sancler
ID: 18743267
.Substring works with a zero-based, not a one-based index.  That should be

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

Roger
0
 

Author Comment

by:sebastiz
ID: 18743295
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
 

Author Comment

by:sebastiz
ID: 18743318
I sorted it- it is a 1 based index, not zero, which is where my error was.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now