Sathish Kothandam
Sathish Kothandam

Reputation: 1520

Remove the character alone from the string

My code retrieves the data from various resources .

And output will be like below

UNY4/4/2010

hds04/5/2010

saths04/22/2013

But I want the output like this

4/4/2010

4/5/2010

04/22/2013

Is there any way to do this ?

Upvotes: 1

Views: 131

Answers (2)

Steven Liekens
Steven Liekens

Reputation: 14088

An alternate solution is to look for the first numeric digit, then discard all text before that.

Function GetDate(data As String) As Date
    Dim indexFirstNum As Integer = data.IndexOfAny("0123456789".ToCharArray())
    Dim datePortion As String = data.Substring(indexFirstNum)
    Return Date.Parse(datePortion)
End Function

Upvotes: 1

Karl Anderson
Karl Anderson

Reputation: 34846

You need to use a regular expression that finds all uppercase and lowercase characters and replaces them with a blank, like this:

Dim rgx As New Regex("[a-zA-Z]")
str = rgx.Replace(str, String.Empty)

Upvotes: 2

Related Questions