Reputation: 1
i am new at Progress openedge! I would like to know how to split a user entered String with using procedure! length of string could be max 2000 and every single Line contains max 35 Character.And spaces between Words must be also to considered.if a single line max > 35 then must begin with another line but not like this : ....hel lo.........
it has to after 35.Line cutting off and spring next line but the spaces make me so confused and i cant find any Algorithm For example:
myfield2 = "Many districts and landmarks in New York City are well known, and the city received a record 62.8 million tourists in 2017".
if index(myfield2,spacee) = 0 then do:
do while ii < length(myfield2) :
line = substring(myfield2,ii,35).
ii = ii + 35.
end.
end.
display line.
else if index(myfield2,spacee) <> 0 and length(myfield2) < 35 then do:
.......
sth like this ?
thank you!
Upvotes: 0
Views: 466
Reputation: 14020
Another approach:
define variable t as character no-undo.
define variable x as character no-undo format "x(36)".
define variable i as integer no-undo.
define variable n as integer no-undo.
t = "Many districts and landmarks in New York City are well known, and the city received a record 62.8 million tourists in 2017".
n = num-entries( t, " " ).
do i = 1 to n:
if length( x + entry( i, t, " " )) < 35 then
do:
x = x + entry( i, t, " " ) + " ".
next.
end.
display x with frame a down.
down 1 with frame a.
x = entry( i, t, " " ) + " ".
end.
display x with frame a down.
or, if you prefer a variable with embedded newlines:
define variable t as character no-undo.
define variable x as character no-undo format "x(36)".
define variable i as integer no-undo.
define variable j as integer no-undo.
define variable n as integer no-undo.
t = "Many districts and landmarks in New York City are well known, and the city received a record 62.8 million tourists in 2017".
n = num-entries( t, " " ).
do i = 1 to n:
if j < 35 and
(j + length( entry( i, t, " " )) + 1) < 35 then
do:
x = x + entry( i, t, " " ) + " ".
j = j + length( entry( i, t, " " )) + 1.
next.
end.
j = length( entry( i, t, " " )) + 1.
x = x + "~n" + entry( i, t, " " ) + " ".
end.
display x view-as editor size 40 by 10.
Upvotes: 1
Reputation: 102
Try something like this. Should be work for you. It breaks the text into a temp table. You can break text to any text length you desire, just by adjusting the second parameter from procedure call.
def temp-table tt-editor no-undo
field linha as integer
field conteudo as character format 'x(80)':U
index editor-id is primary unique
linha.
procedure pi-print-editor:
def input param c-editor as char no-undo.
def input param i-len as integer no-undo.
def var i-linha as integer no-undo.
def var i-aux as integer no-undo.
def var c-aux as char no-undo.
def var c-ret as char no-undo.
IF c-editor = ? or i-len = ? THEN
RETURN.
for each tt-editor:
delete tt-editor.
end.
assign c-ret = chr(255) + chr(255).
do while c-editor <> "":
if c-editor <> "" then do:
assign i-aux = index(c-editor, chr(10)).
IF i-aux = 0 THEN DO:
assign i-aux = index(c-editor, chr(13)).
END.
if i-aux > i-len or (i-aux = 0 and length(c-editor) > i-len) then
assign i-aux = r-index(c-editor, " ", i-len + 1).
if i-aux = 0 then
assign c-aux = substr(c-editor, 1, i-len)
c-editor = substr(c-editor, i-len + 1).
else
assign c-aux = substr(c-editor, 1, i-aux - 1)
c-editor = substr(c-editor, i-aux + 1).
if i-len = 0 then
assign entry(1, c-ret, chr(255)) = c-aux.
else do:
assign i-linha = i-linha + 1.
create tt-editor.
assign tt-editor.linha = i-linha
tt-editor.conteudo = c-aux.
end.
end.
if i-len = 0 then
return c-ret.
end.
return c-ret.
end procedure.
RUN pi-print-editor ('modtemLoremipsumdolorsitametconsetetursadipscingelitrseddiamnonumyeirporinviduntutlaboreet.Commentsusedtoasforclarificationoro. i mean the text without spaces.',35).
FOR EACH tt-editor:
DISP tt-editor.conteudo FORMAT 'x(40)' LENGTH(conteudo) WITH WIDTH 333.
END.
Hope it helps.
Upvotes: 0
Reputation: 7192
Something like this:
DEFINE VARIABLE cInput AS CHARACTER NO-UNDO INITIAL
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et ~
dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet ~
clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, ~
consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, ~
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea ~
takimata sanctus est Lorem ipsum dolor sit amet.".
DEFINE VARIABLE cOutput AS CHARACTER NO-UNDO.
DEFINE VARIABLE iPos AS INTEGER NO-UNDO.
DEFINE VARIABLE iPrev AS INTEGER NO-UNDO INITIAL 1 .
DEFINE VARIABLE iLength AS INTEGER NO-UNDO.
ASSIGN iLength = LENGTH (cInput, "CHARACTER").
repeatLoop:
REPEAT:
iPos = R-INDEX (cInput, " ", iPrev + 35) .
IF iPos = 0 THEN
ASSIGN iPos = iLength .
ASSIGN cOutput = cOutput + TRIM (SUBSTRING (cInput, iPrev, iPos - iPrev, "CHARACTER")) + "|~n".
IF iPos + 35 >= iLength THEN DO:
ASSIGN cOutput = cOutput + TRIM (SUBSTRING (cInput, iPos, -1, "CHARACTER")) .
LEAVE repeatLoop.
END.
ASSIGN iPrev = iPos .
END.
MESSAGE cOutput
VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
Upvotes: 0
Reputation: 7192
You can find the space character left to your 35th character using R-INDEX
R-INDEX (myfield2, " ", ii) .
Upvotes: 1