Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Please help me convert the C# code to VB.Net

Please help me convert the C# code to VB.Net

Scheduled Pinned Locked Moved C#
csharpregexhelptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Support123
    wrote on last edited by
    #1

    Hi, I beleive this sample code is in C#: string cleanString = String.Empty; Regex reg = new Regex("[A-Z]|[a-z]"); MatchCollection coll = reg.Matches(<MyStringGoesHere>); for(int i = 0; i < coll.Count; i++) { cleanString = cleanString + coll[i].Value; } See, i want to remove all characters that do not fall in the A-Z or a-z OR 0-9 category AND replace it with a space... example test123t3er = test t er Am i wrong in saying that the Regex reg = Regex("[A-Z]|[a-z]") CAN IT BE: Regex reg = Regex("[A-Z]|[a-z]|[0-9]") ??? AND the cleanString = cleanString + coll[i].Value; CAN I DO A TEST: IF(coll[i].Value == String.Empty) THEN cleanString = cleanString + " "; ELSE cleanString = cleanString + coll[i].Value ???? - in this way i add space if the character is not in the above category???? So please help me convert the very top section of code and i will build from there... Thank you in advance...

    "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

    P C 2 Replies Last reply
    0
    • S Support123

      Hi, I beleive this sample code is in C#: string cleanString = String.Empty; Regex reg = new Regex("[A-Z]|[a-z]"); MatchCollection coll = reg.Matches(<MyStringGoesHere>); for(int i = 0; i < coll.Count; i++) { cleanString = cleanString + coll[i].Value; } See, i want to remove all characters that do not fall in the A-Z or a-z OR 0-9 category AND replace it with a space... example test123t3er = test t er Am i wrong in saying that the Regex reg = Regex("[A-Z]|[a-z]") CAN IT BE: Regex reg = Regex("[A-Z]|[a-z]|[0-9]") ??? AND the cleanString = cleanString + coll[i].Value; CAN I DO A TEST: IF(coll[i].Value == String.Empty) THEN cleanString = cleanString + " "; ELSE cleanString = cleanString + coll[i].Value ???? - in this way i add space if the character is not in the above category???? So please help me convert the very top section of code and i will build from there... Thank you in advance...

      "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

      P Offline
      P Offline
      Paw Jershauge
      wrote on last edited by
      #2

      I believe this is the VB.Net code Dim cleanString As String = [String].Empty Dim reg As New Regex("[A-Z]|[a-z]") Dim coll As MatchCollection = reg.Matches(<MyStringGoesHere> ) For i As Integer = 0 To coll.Count - 1 cleanString = cleanString + coll(i).Value Next

      S 1 Reply Last reply
      0
      • P Paw Jershauge

        I believe this is the VB.Net code Dim cleanString As String = [String].Empty Dim reg As New Regex("[A-Z]|[a-z]") Dim coll As MatchCollection = reg.Matches(<MyStringGoesHere> ) For i As Integer = 0 To coll.Count - 1 cleanString = cleanString + coll(i).Value Next

        S Offline
        S Offline
        Support123
        wrote on last edited by
        #3

        wow, thanks... that was super fast.... :-D

        "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

        P 1 Reply Last reply
        0
        • S Support123

          wow, thanks... that was super fast.... :-D

          "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

          P Offline
          P Offline
          Paw Jershauge
          wrote on last edited by
          #4

          Your welcome ;)

          1 Reply Last reply
          0
          • S Support123

            Hi, I beleive this sample code is in C#: string cleanString = String.Empty; Regex reg = new Regex("[A-Z]|[a-z]"); MatchCollection coll = reg.Matches(<MyStringGoesHere>); for(int i = 0; i < coll.Count; i++) { cleanString = cleanString + coll[i].Value; } See, i want to remove all characters that do not fall in the A-Z or a-z OR 0-9 category AND replace it with a space... example test123t3er = test t er Am i wrong in saying that the Regex reg = Regex("[A-Z]|[a-z]") CAN IT BE: Regex reg = Regex("[A-Z]|[a-z]|[0-9]") ??? AND the cleanString = cleanString + coll[i].Value; CAN I DO A TEST: IF(coll[i].Value == String.Empty) THEN cleanString = cleanString + " "; ELSE cleanString = cleanString + coll[i].Value ???? - in this way i add space if the character is not in the above category???? So please help me convert the very top section of code and i will build from there... Thank you in advance...

            "Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

            C Offline
            C Offline
            ChrisKo 0
            wrote on last edited by
            #5

            You could easily do this in a RegEx by itself and avoid looping through the matches. \W captures all non-word characters (anything not a-z A-Z or 0-9), so you can then just use the Replace method of the Regex class.

            Dim resultString As String
            resultString = System.Text.RegularExpressions.Regex.Replace("ABC$%123*>890!#XYZ", "\W", " ")

            I haven't done VB since VB6, but I assume that should work as it's a simple statement.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups