www.webdeveloper.com
Results 1 to 4 of 4

Thread: Replace function

  1. #1
    Join Date
    Apr 2003
    Location
    Vermont (USA)
    Posts
    343

    Replace function

    I need to replace an expression that occurs from time to time when parsing a file.

    How would I replace every occurrence of \r\n****\r\n with nothing ""

    So it would be a line return (\r\n) a 4 digit (numbers and letters) identifier then a line return(\r\n). Replace that with just blank (basically remove it).

    Example would be \r\n1e25\r\n or
    1e25

    And then it would remove that whole thing from the string.

    I'm not too good with regular expressions how would i go about that?

    Thanks

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    String has a function replaceAll() use that and it should take care of ur issue
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Apr 2003
    Location
    Vermont (USA)
    Posts
    343

    ya

    ya i know... what would the regex be?

    "\r\n....\r\n"

    Something like that?

  4. #4
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,120
    here it is , as simple as it can possibly get.

    String d = "\r\n1e25\r\n\r\n2e26\r\n\r\n3e27\r\n\r\n4e28\r\n";
    //there are 2 simple ways you can do it with, use split method or replaceAll

    System.out.println("["+d+"]\n["+d.replaceAll("\r\n"," ")+"]");
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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



Recent Articles