Пользователь вошел в разделение строк - PullRequest
0 голосов
/ 07 мая 2018

Я новичок в открытии Прогресса! Я хотел бы знать, как разделить введенную пользователем строку на с помощью процедуры ! длина строки может быть не более 2000, и каждая отдельная строка содержит не более 35 символов. И пробелы между словами также должны учитываться. Если одна строка макс.> 35, то должна начинаться с другой строки, но не так: .... hel вот .........

это должно произойти после 35. Строка обрезается и начинается следующая строка, но пробелы приводят меня в замешательство, и я не могу найти какой-либо алгоритм Например:

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: 

.......

что-то вроде этого?

спасибо!

Ответы [ 4 ]

0 голосов
/ 08 мая 2018

Попробуйте что-нибудь подобное. Должно быть работа для вас. Он разбивает текст на временную таблицу. Вы можете разбить текст на любую желаемую длину, просто изменив второй параметр из вызова процедуры.

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.

Надеюсь, это поможет.

0 голосов
/ 07 мая 2018

Другой подход:

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.

или, если вы предпочитаете переменную со встроенными символами новой строки:

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.
0 голосов
/ 08 мая 2018

Примерно так:

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.
0 голосов
/ 07 мая 2018

Вы можете найти пробел слева от вашего 35-го символа, используя R-INDEX

R-INDEX (myfield2, " ", ii) .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...