INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Regex

Regex

(OP)

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


RE: Regex

This is a strange error, as there is indeed a Regex.Replace method that takes 3 string parameters: https://msdn.microsoft.com/en-us/library/e7f5w83z%...

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!

RE: Regex

(OP)
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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close