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. Web Development
  3. ASP.NET
  4. Replace Method case insensitive

Replace Method case insensitive

Scheduled Pinned Locked Moved ASP.NET
csharpalgorithms
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.
  • A Offline
    A Offline
    awu25
    wrote on last edited by
    #1

    This is what I do with ASP3.0. If a user enters "This is green color" I want to first search if the word "green" color exists then replace the word "green" with <font color=green>green</font>. When searching for the word I don't need it to be case sensitive and when replacing the word I want to preserve the case. For exmple, if user enters "This is GrEEn color" I want to replace the word GrEEn with <font color=GrEEn>GrEEn</font>. This is pretty easy with VB's case insensitive instr and replace but I can't seem to find a simple solution in C#

    N 1 Reply Last reply
    0
    • A awu25

      This is what I do with ASP3.0. If a user enters "This is green color" I want to first search if the word "green" color exists then replace the word "green" with <font color=green>green</font>. When searching for the word I don't need it to be case sensitive and when replacing the word I want to preserve the case. For exmple, if user enters "This is GrEEn color" I want to replace the word GrEEn with <font color=GrEEn>GrEEn</font>. This is pretty easy with VB's case insensitive instr and replace but I can't seem to find a simple solution in C#

      N Offline
      N Offline
      NewSilence
      wrote on last edited by
      #2

      awu25 wrote: if user enters "This is GrEEn color" I want to replace the word GrEEn with GrEEn. try regular expressions Dim r As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("red", System.Text.RegularExpressions.RegexOptions.IgnoreCase) Dim s As String = "word1 word2 reD word3" Dim s2 As String = r.Match(s).Value Dim res As String = r.Replace(s, "[font color=" & s2 & "]" & s2 & "[/font]")

      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