Replacing Punctuation


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Replacing Punctuation

Hybrid View

  1. #1
    Join Date
    Apr 2006
    Posts
    3

    Replacing Punctuation

    hi all,

    Im trying to replace all mentions of .html in a html fine to .jsp. For example if i had:

    <html>
    <h1>
    Some Text Here
    </h1>
    <a href ="page1.html"> Go to Page1
    </html>

    i would want to ONLY replace the .html in the link.

    By using:


    String replace= src.replaceAll(".html", ".jsp");



    i succesfully replace the .html in the link but i also replace the html at the start and at the beginning despite them not having a "." in front of them? Any ideas on how to fix this PLEASE

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Look at the Pattern class, search to match the pattern.

    Did you try to use an escape code before the period? ("\.html")

  3. #3
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    it should be ("\\.html"), since \ has to be escaped within strings with \\. the dot is the regular expression for anycharacter.

Similar Threads

  1. Replies: 13
    Last Post: 10-03-2007, 07:47 AM
  2. Replacing parts of a string
    By rssmps in forum C++
    Replies: 1
    Last Post: 12-31-2005, 08:38 PM
  3. Replacing a string.
    By Dennis in forum Database
    Replies: 2
    Last Post: 01-23-2003, 12:50 PM
  4. Replacing \x and \u to x and u.
    By Jose Rodz in forum Java
    Replies: 1
    Last Post: 11-15-2002, 03:41 PM
  5. Is NET replacing COM ?
    By MrRolf in forum .NET
    Replies: 35
    Last Post: 05-28-2002, 06:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center