You must Sign In to post a response.
  • Category: SQL Server

    Replace paritucular keywords from string exact match

    i want to replace some short forms of words with its full form from decription column of one table. These short forms are stored in table .This table have columns like short_form ,long_form
    e.g 4wd 4 wheel drive
    2wd 2 wheel drive

    we have description like
    1)John Deere 7210 Tractor.<br> $45,000. <br>4WD, <br>6700hrs, <br>quad range.
    2)4wd,new 11.2X24 rears 7 X 16 fronts,Frey 4010S loader with quick attach bucket & forks, 3pt hitch,
    3)w/9116 16" FH, 1163 6R CH, 4wd, chopper, grey cab model, Mildmay, 800-829-2672

    we have to replace 4wd with 4 wheel drive [this should be taken from values stored in table] .We need to replace exact match from description column. e.g 4wd,new 11.2X24 rears 7 X 16 fronts,Frey 4010S loader with quick attach bucket & forks, 3pt hitch, should be 4 wheel drive,new 11.2X24 rears 7 X 16 fronts,Frey 4010S loader with quick attach bucket & forks, 3pt hitch,
    , or any other special character should be escaped.
  • #769390
    Hi Smita,
    Use regex like:
    string myinput="John Deere 7210 Tractor.<br> $45,000. <br>4WD, <br>6700hrs, <br>quad range."
    string result = Regex.Replace(myinput, @"\b4wd\b", " 4 wheel drive ", RegexOptions.IgnoreCase);

  • #769393
    Nice suggestion...

  • #769395
    Nice solution . very helpful blog for me bcz i have been facing problem regarding this issue since two week . now i feel relax and happy having read you bolg and i done my work by your blog.it really very helpful . thnaks

  • #769396
    Thanks mukesh............I'm glad to know that this code is useful for you .

  • #769398
    I want to do from database query

  • #769399
    In sql you can use Replace function.
    Like:

    UPDATE tbl
    SET short_form= REPLACE(short_form, '4wd', '4 wheel drive')


  • Sign In to post your comments