Deleting a specific sequence of characters (linebreaks?) from astring

Discussion in 'Ruby' started by Aldric Giacomoni, Feb 18, 2009.

  1. I need to delete a sequence of characters like '\\n' from a string - but I don't want to delete every 'n' and every '\' from it! So .. "delete" doesn't seem to be an option and I can't get "gsub" to do what I want. Is there a tried and true solution that I just haven't found? Here is an example test, straight from the document itself:

    Soft linebreaks are linebreaks preceeded by '\\' like this one >o\
    k<. Hard line breaks are all other linebreaks.
    Soft linebreaks are converted to >nothing<, i.e. removed.

    Note that linebreaks are coded differently on different systems.

    Examples (>ok< shouldn't be split):

    linebreak 1 "\\n": >o\
    k<
    linebreak 2 "\\n\\r": >o\

    k<
    linebreak 3 "\\r\\n": >o\
    k<
    linebreak 4 "\\r": >o\
    k<]


    Expected result is that >ok< looks normal on all lines - I don't know how to make that happen. Can anyone enlighten me .. Or put me on the path?

    Thanks,
    --Aldric
    Aldric Giacomoni, Feb 18, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew
    Replies:
    5
    Views:
    6,959
    John C. Bollinger
    Sep 28, 2004
  2. Behrang Dadsetan

    Deleting specific characters from a string

    Behrang Dadsetan, Jul 9, 2003, in forum: Python
    Replies:
    17
    Views:
    713
    Bengt Richter
    Jul 11, 2003
  3. Michael Chermside

    RE: Deleting specific characters from a string

    Michael Chermside, Jul 10, 2003, in forum: Python
    Replies:
    1
    Views:
    315
    Paul Rudin
    Jul 10, 2003
  4. Replies:
    10
    Views:
    596
    Torsten Bronger
    Dec 31, 2007
  5. grbgooglefan
    Replies:
    2
    Views:
    409
    Pascal Bourguignon
    Jan 30, 2008
Loading...

Share This Page