String manipulation

Discussion in 'C++' started by aloha826@gmail.com, Jan 6, 2009.

  1. Guest

    Hi,

    I need to break a string into few words in case of exceeding 16 chars

    For example:
    the string has:
    "This is just only for testing"

    with limit of 16 chars, it reach: "This is just onl"

    so, I need to break it to next line at the last occurance of space of
    the 16 chars:
    so it will be:
    "This is just"
    "only for testing"

    if the 2nd line is exceeding 16 chars, it will break at last occurance
    of space, and move to next line

    can anyone provide this function ?

    Regards.
    , Jan 6, 2009
    #1
    1. Advertising

  2. Kai-Uwe Bux Guest

    wrote:

    > Hi,
    >
    > I need to break a string into few words in case of exceeding 16 chars
    >
    > For example:
    > the string has:
    > "This is just only for testing"
    >
    > with limit of 16 chars, it reach: "This is just onl"
    >
    > so, I need to break it to next line at the last occurance of space of
    > the 16 chars:
    > so it will be:
    > "This is just"
    > "only for testing"
    >
    > if the 2nd line is exceeding 16 chars, it will break at last occurance
    > of space, and move to next line


    a) What shall happen when a word is more than 16 chars?

    b) What did you try and which problems did you observe?



    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Jan 6, 2009
    #2
    1. Advertising

  3. Default User Guest

    wrote:

    > Hi,
    >
    > I need to break a string into few words in case of exceeding 16 chars



    First, decide on which language you are using. You multi-posted this to
    at least two newsgroups (comp.lang.c and the least).




    Brian
    Default User, Jan 6, 2009
    #3
  4. James Kanze Guest

    On Jan 6, 8:38 pm, "" <> wrote:

    > I need to break a string into few words in case of exceeding 16 chars


    > For example:
    > the string has:
    > "This is just only for testing"


    > with limit of 16 chars, it reach: "This is just onl"


    > so, I need to break it to next line at the last occurance of space of
    > the 16 chars:
    > so it will be:
    > "This is just"
    > "only for testing"


    > if the 2nd line is exceeding 16 chars, it will break at last occurance
    > of space, and move to next line


    > can anyone provide this function ?


    You'll have to define it a bit more exactly. I've code for
    formatting comments, for example, which does line breaking, but
    it may not be what you're looking for.

    The basic algorithm is simple: break the input up into words,
    and pass these over to a formatter, which determines whether
    they will fit on the current line or not. This is the most
    flexible solution, since it is easily extended to handle various
    types of markup. (If memory serves me correctly, I got the
    basic algorithm from "Programming Tools in Pascal", by Kernighan
    and Plauger. Still one of the best books around, despite its
    age, and the fact that its authors insist on writing C in
    Pascal.)

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Jan 7, 2009
    #4
    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. jared in ecs

    Perl string manipulation

    jared in ecs, Oct 22, 2003, in forum: Perl
    Replies:
    2
    Views:
    806
    Roy Johnson
    Oct 22, 2003
  2. Garfield

    String Array Manipulation Problem

    Garfield, Aug 27, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    2,811
    Michael Lang
    Aug 27, 2003
  3. Aaron

    String Manipulation

    Aaron, Dec 31, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    4,624
    Dave Davidson
    Dec 31, 2003
  4. Aaron

    Advanced String Manipulation (C#)

    Aaron, Jan 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    816
  5. Chris

    String manipulation

    Chris, May 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    450
    Pete Wright
    May 24, 2004
Loading...

Share This Page