用户输入了字符串拆分

时间:2018-05-07 10:02:48

标签: openedge progress-4gl

我是Progress openge的新人!我想知道如何用使用过程拆分用户输入的字符串! 字符串的长度可以是最大2000,并且每一行包含最多35个字符。还必须考虑字之间的空格。如果单行最大值> 35然后必须从另一条线开始但不是这样的:.... hel                                                                    LO .........

它必须在35.Line切断和弹簧下一行但空间让我如此困惑,我无法找到任何算法 例如:

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 :(得分:1)

您可以使用R-INDEX

找到第35个字符的空格字符

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

答案 1 :(得分:1)

另一种方法:

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.

答案 2 :(得分:0)

这样的事情:

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.

答案 3 :(得分:0)

尝试这样的事情。应该适合你。它将文本分成临时表。只需调整过程调用中的第二个参数,即可将文本分解为所需的任何文本长度。

this.setState({ data: filteredByPriority });

希望它有所帮助。