String manipulation

A

aloha826

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.
 
K

Kai-Uwe Bux

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
 
D

Default User

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
 
J

James Kanze

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top