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
  1. Home
  2. General Programming
  3. Visual Basic
  4. having trouble replacing Trademark and Registered symbol with Regex

having trouble replacing Trademark and Registered symbol with Regex

Scheduled Pinned Locked Moved Visual Basic
debuggingregextutorialquestion
2 Posts 2 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.
  • D Offline
    D Offline
    David Mujica
    wrote on last edited by
    #1

    I'm trying to remove the ® and ™ symbols in a string using Regex and it doesnt work for the ™ symbol. Here is some example code:

    Dim s1, s2, s3 As String
    Dim i As Integer

      s1 = "Trademark" + Chr(153) + " Registered" + Chr(174)
    
    
      s2 = System.Text.RegularExpressions.Regex.Replace(s1, "\[\\x99\]", "(TM)")
      s3 = System.Text.RegularExpressions.Regex.Replace(s1, "\[\\xAE\]", "(R)")
    
    
      Debug.Print("Orig: " + s1)
      For i = 0 To s1.Length - 1
          Debug.Print("     " + s1.Substring(i, 1) + " " + Asc(s1.Substring(i, 1)).ToString("X") + " " + Asc(s1.Substring(i, 1)).ToString)
      Next
    
      Debug.Print("S2  :  " + s2)
      Debug.Print("S3  :  " + s3)
    

    This code seems to work for the (R) symbol, but not the (TM). However, if I use Chr(153) instead of \x99 in the regex call, the code works fine. What am I doing wrong? Thanks.

    L 1 Reply Last reply
    0
    • D David Mujica

      I'm trying to remove the ® and ™ symbols in a string using Regex and it doesnt work for the ™ symbol. Here is some example code:

      Dim s1, s2, s3 As String
      Dim i As Integer

        s1 = "Trademark" + Chr(153) + " Registered" + Chr(174)
      
      
        s2 = System.Text.RegularExpressions.Regex.Replace(s1, "\[\\x99\]", "(TM)")
        s3 = System.Text.RegularExpressions.Regex.Replace(s1, "\[\\xAE\]", "(R)")
      
      
        Debug.Print("Orig: " + s1)
        For i = 0 To s1.Length - 1
            Debug.Print("     " + s1.Substring(i, 1) + " " + Asc(s1.Substring(i, 1)).ToString("X") + " " + Asc(s1.Substring(i, 1)).ToString)
        Next
      
        Debug.Print("S2  :  " + s2)
        Debug.Print("S3  :  " + s3)
      

      This code seems to work for the (R) symbol, but not the (TM). However, if I use Chr(153) instead of \x99 in the regex call, the code works fine. What am I doing wrong? Thanks.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      chr() and asc() are ancient ANSI-oriented functions. A little experiment taught me chr(153) generates unicode character x2122. Using AscW() rather than Asc() would reveal the truth about your strings. :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum


      Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.

      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