text formatting question

Discussion in 'Python' started by idy, Mar 1, 2013.

  1. idy

    idy Guest

    I have a text string of this format

    Error = 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.1111111LOcation/user/data/INGE-FTYXYC.3333333LOcation/user/data/GETN-YUN'

    I need to write this to mail body as with following format in multiple lines

    XYC.12345455-LOcation/user/data/MYGLE-ING
    XYC.23344566-LOcation/user/data/INGE-FTY
    XYC.22334566LOcation/user/data/GETN-YUN
    XYC.12345455LOcation/user/data/MYGLE-ING
    XYC.1111111LOcation/user/data/INGE-FTY
    XYC.3333333LOcation/user/data/GETN-YUN

    Note (XYC is common for all the text , rest of the fields are not constant. Please help
     
    idy, Mar 1, 2013
    #1
    1. Advertising

  2. On Fri, Mar 1, 2013 at 5:49 PM, idy <> wrote:
    > Error = 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.1111111LOcation/user/data/INGE-FTYXYC.3333333LOcation/user/data/GETN-YUN'
    >
    > I need to write this to mail body as with following format in multiple lines
    >
    > XYC.12345455-LOcation/user/data/MYGLE-ING
    > XYC.23344566-LOcation/user/data/INGE-FTY
    > XYC.22334566LOcation/user/data/GETN-YUN
    > XYC.12345455LOcation/user/data/MYGLE-ING
    > XYC.1111111LOcation/user/data/INGE-FTY
    > XYC.3333333LOcation/user/data/GETN-YUN


    You want to break the line immediately before the 'XYC'? That's quite
    easy; the line break is a character like any other, and can be used in
    a replace() call:

    formatted_error = Error.replace("XYC","\nXYC")

    If that's not the case, can you clarify what you need to do to divide it?

    Chris Angelico
     
    Chris Angelico, Mar 1, 2013
    #2
    1. Advertising

  3. idy

    idy Guest

    On Friday, March 1, 2013 12:23:41 PM UTC+5:30, Chris Angelico wrote:
    > On Fri, Mar 1, 2013 at 5:49 PM, idy <> wrote:
    >
    > > Error = 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.1111111LOcation/user/data/INGE-FTYXYC.3333333LOcation/user/data/GETN-YUN'

    >
    > >

    >
    > > I need to write this to mail body as with following format in multiple lines

    >
    > >

    >
    > > XYC.12345455-LOcation/user/data/MYGLE-ING

    >
    > > XYC.23344566-LOcation/user/data/INGE-FTY

    >
    > > XYC.22334566LOcation/user/data/GETN-YUN

    >
    > > XYC.12345455LOcation/user/data/MYGLE-ING

    >
    > > XYC.1111111LOcation/user/data/INGE-FTY

    >
    > > XYC.3333333LOcation/user/data/GETN-YUN

    >
    >
    >
    > You want to break the line immediately before the 'XYC'? That's quite
    >
    > easy; the line break is a character like any other, and can be used in
    >
    > a replace() call:
    >
    >
    >
    > formatted_error = Error.replace("XYC","\nXYC")
    >
    >
    >
    > If that's not the case, can you clarify what you need to do to divide it?
    >
    >
    >
    > Chris Angelico


    Chris,

    Thanks this works great !!!
     
    idy, Mar 1, 2013
    #3
  4. idy

    idy Guest

    On Friday, March 1, 2013 12:23:41 PM UTC+5:30, Chris Angelico wrote:
    > On Fri, Mar 1, 2013 at 5:49 PM, idy <> wrote:
    >
    > > Error = 'XYC.12345455LOcation/user/data/MYGLE-INGXYC.23344566LOcation/user/data/INGE-FTYXYC.22334566LOcation/user/data/GETN-YUNXYC.12345455LOcation/user/data/MYGLE-INGXYC.1111111LOcation/user/data/INGE-FTYXYC.3333333LOcation/user/data/GETN-YUN'

    >
    > >

    >
    > > I need to write this to mail body as with following format in multiple lines

    >
    > >

    >
    > > XYC.12345455-LOcation/user/data/MYGLE-ING

    >
    > > XYC.23344566-LOcation/user/data/INGE-FTY

    >
    > > XYC.22334566LOcation/user/data/GETN-YUN

    >
    > > XYC.12345455LOcation/user/data/MYGLE-ING

    >
    > > XYC.1111111LOcation/user/data/INGE-FTY

    >
    > > XYC.3333333LOcation/user/data/GETN-YUN

    >
    >
    >
    > You want to break the line immediately before the 'XYC'? That's quite
    >
    > easy; the line break is a character like any other, and can be used in
    >
    > a replace() call:
    >
    >
    >
    > formatted_error = Error.replace("XYC","\nXYC")
    >
    >
    >
    > If that's not the case, can you clarify what you need to do to divide it?
    >
    >
    >
    > Chris Angelico


    Chris,

    Thanks this works great !!!
     
    idy, Mar 1, 2013
    #4
  5. idy

    Dave Angel Guest

    On 03/01/2013 02:08 AM, idy wrote:
    > On Friday, March 1, 2013 12:23:41 PM UTC+5:30, Chris Angelico wrote:
    >>
    >>
    >>> <snip>

    >>
    >> You want to break the line immediately before the 'XYC'? That's quite
    >> easy; the line break is a character like any other, and can be used in
    >> a replace() call:
    >>
    >> formatted_error = Error.replace("XYC","\nXYC")
    >>
    >> If that's not the case, can you clarify what you need to do to divide it?
    >>
    >> Chris Angelico

    >
    > Chris,
    >
    > Thanks this works great !!!
    >


    The assumption Chris made is that the characters XYC do *not* appear
    anywhere else in each string. if they do, then you need to write a spec
    as to what criteria you can count on for the data.

    If somebody has mangled all those lines into one long string, it's quite
    likely that they CANNOT be reliably separated again. Chris' suggestion
    is the most likely candidate, but ...
    --
    DaveA
     
    Dave Angel, Mar 1, 2013
    #5
  6. On Sat, Mar 2, 2013 at 12:52 AM, Dave Angel <> wrote:
    > The assumption Chris made is that the characters XYC do *not* appear
    > anywhere else in each string. if they do, then you need to write a spec as
    > to what criteria you can count on for the data.
    >


    Right. I should have mentioned that. Let's hope the OP is sufficiently
    lucky as to have a separator uniqueness..


    ChrisA
     
    Chris Angelico, Mar 1, 2013
    #6
    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. Winanjaya Amidjojo

    Re: formatting text in textbox while typing

    Winanjaya Amidjojo, Jul 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    448
    Winanjaya Amidjojo
    Jul 3, 2003
  2. ald
    Replies:
    0
    Views:
    369
  3. avnrao
    Replies:
    1
    Views:
    689
    =?Utf-8?B?dG9ueQ==?=
    May 13, 2004
  4. Swanand Mokashi
    Replies:
    0
    Views:
    624
    Swanand Mokashi
    May 13, 2004
  5. Dr. Who

    HTML/text formatting question

    Dr. Who, Aug 3, 2005, in forum: Python
    Replies:
    2
    Views:
    296
    Edvard Majakari
    Aug 25, 2005
Loading...

Share This Page