Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex

Status
Not open for further replies.

TrekBiker

Technical User
Nov 26, 2010
330
0
0
GB

A VB project I've inherited contains this

Code:
Dim [clean_string] As String = Regex.Replace(scanCode, "[^0-9a-zA-Z\> ]+?", "")

I want to replicate this in a new form in the same project but it's giving this error.

Error : Overload resolution failed because no accessible 'Replace' can be called without a narrowing conversion:
'Public Function Replace(input As String, replacement As String, count As Integer) As String': Argument matching parameter 'input' narrows from 'Integer' to 'String'.
'Public Function Replace(input As String, replacement As String, count As Integer) As String': Argument matching parameter 'count' narrows from 'String' to 'Integer'.

What's likely to be missing? I've copied over this line at the start of the code but to no avail.
Imports System.Text.RegularExpressions


 
This is a strange error, as there is indeed a Regex.Replace method that takes 3 string parameters:
Are you sure that scanCode is a string?


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks for response. I created a form with text box Raw so I could check what CleanString produces after entering a value and clicking Button1.

This is the complete code, as far as I got.

Code:
Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim scanCode As String = Raw.Text
        Dim PCode As String
        Dim CleanString As String = Regex.Replace(scanCode, "[^0-9a-zA-Z\> ]+?", "")
        scanCode = scanCode.Substring(4, scanCode.Length - 4)
        PCode = scanCode
    End Sub

End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top