Solved

Delete characters after a whitespace

Posted on 2007-03-18
4
394 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 143

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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.

726 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