how would I trim a mix of newline and space characters from the beginning and en

how would I trim a mix of newline and space characters from the beginning and end of a text string? For example,
"
this is
a string

" becomes
"this is
a string"

OriginalPostID-174728

OriginalPostID-174728

  Discussion posts and replies are publicly visible

Parents
  • To remove mix of newline and space characters in the beginning of a text

    Create two rules which works in recursive manner

    rule1:

    with(
    local!regexMatch:if(rule!APN_isBlank(ri!input),{},
    regexfirstmatch({"^[\s]+|[\s]+$]"},ri!input)),
    local!correctvalue:
    if(rule!APN_isBlank(local!regexMatch),{},
    replace(ri!input,1,(search(local!regexMatch,ri!input,1)),"")),
    if(rule!APN_isEmpty(local!correctvalue),ri!input,
    if(rule!APN_isBlank(regexfirstmatch({"^[\s]+|[\s]+$]"},local!correctvalue)),local!correctvalue,
    rule!rule2(input:local!correctvalue))))

     

    rule2:

    with(
    local!regexMatch:if(rule!APN_isBlank(ri!input),{},
    regexfirstmatch({"^[\s]+|[\s]+$]"},ri!input)),
    local!correctvalue:
    if(rule!APN_isBlank(local!regexMatch),{},
    replace(ri!input,1,(search(local!regexMatch,ri!input,1)),"")),
    if(rule!APN_isEmpty(local!correctvalue),ri!input,
    if(rule!APN_isBlank(regexfirstmatch({"^[\s]+|[\s]+$]"},local!correctvalue)),local!correctvalue,
    rule!rule1(input:local!correctvalue))))

     

    saveInto in the interface:

    saveInto: {
    a!save(local!input,save!value),
    a!save(
    ri!input,if(regexmatch("^[ \n]*$",save!value),{},
    rule!rule1(input:save!value)))}

    To remove mix of newline and space characters at the end of a text

    Create two rules which works in recursive manner

    rule1:

    with(
    local!length:len(ri!input),
    local!regexMatch:if(rule!APN_isBlank(ri!input),{},
    regexmatch({"[$|\s]"},index(ri!input,local!length,{}))),
    local!correctvalue:
    if(local!regexMatch,
    replace(ri!input,local!length,1,""),{}),
    if(rule!APN_isEmpty(local!correctvalue),ri!input,
    if(regexmatch({"[$|\s]"},index(local!correctvalue,len(local!correctvalue),{})),
    rule!rule2(input:local!correctvalue),
    local!correctvalue,
    )))

    rule2:

    with(
    local!length:len(ri!input),
    local!regexMatch:if(rule!APN_isBlank(ri!input),{},
    regexmatch({"[$|\s]"},index(ri!input,local!length,{}))),
    local!correctvalue:
    if(local!regexMatch,
    replace(ri!input,local!length,1,""),{}),
    if(rule!APN_isEmpty(local!correctvalue),ri!input,
    if(regexmatch({"[$|\s]"},index(local!correctvalue,len(local!correctvalue),{})), 
    rule!rule1(input:local!correctvalue),
    local!correctvalue,
    )))

    SaveInto in the interface:

    saveInto: {
    a!save(local!input,save!value),
    a!save(
    ri!input,
    rule!rule1(input:save!value))}

    to remove empty space in the beginning and at end, in save into call these rules one after the other and then save value

    Hope this helps

Reply
  • To remove mix of newline and space characters in the beginning of a text

    Create two rules which works in recursive manner

    rule1:

    with(
    local!regexMatch:if(rule!APN_isBlank(ri!input),{},
    regexfirstmatch({"^[\s]+|[\s]+$]"},ri!input)),
    local!correctvalue:
    if(rule!APN_isBlank(local!regexMatch),{},
    replace(ri!input,1,(search(local!regexMatch,ri!input,1)),"")),
    if(rule!APN_isEmpty(local!correctvalue),ri!input,
    if(rule!APN_isBlank(regexfirstmatch({"^[\s]+|[\s]+$]"},local!correctvalue)),local!correctvalue,
    rule!rule2(input:local!correctvalue))))

     

    rule2:

    with(
    local!regexMatch:if(rule!APN_isBlank(ri!input),{},
    regexfirstmatch({"^[\s]+|[\s]+$]"},ri!input)),
    local!correctvalue:
    if(rule!APN_isBlank(local!regexMatch),{},
    replace(ri!input,1,(search(local!regexMatch,ri!input,1)),"")),
    if(rule!APN_isEmpty(local!correctvalue),ri!input,
    if(rule!APN_isBlank(regexfirstmatch({"^[\s]+|[\s]+$]"},local!correctvalue)),local!correctvalue,
    rule!rule1(input:local!correctvalue))))

     

    saveInto in the interface:

    saveInto: {
    a!save(local!input,save!value),
    a!save(
    ri!input,if(regexmatch("^[ \n]*$",save!value),{},
    rule!rule1(input:save!value)))}

    To remove mix of newline and space characters at the end of a text

    Create two rules which works in recursive manner

    rule1:

    with(
    local!length:len(ri!input),
    local!regexMatch:if(rule!APN_isBlank(ri!input),{},
    regexmatch({"[$|\s]"},index(ri!input,local!length,{}))),
    local!correctvalue:
    if(local!regexMatch,
    replace(ri!input,local!length,1,""),{}),
    if(rule!APN_isEmpty(local!correctvalue),ri!input,
    if(regexmatch({"[$|\s]"},index(local!correctvalue,len(local!correctvalue),{})),
    rule!rule2(input:local!correctvalue),
    local!correctvalue,
    )))

    rule2:

    with(
    local!length:len(ri!input),
    local!regexMatch:if(rule!APN_isBlank(ri!input),{},
    regexmatch({"[$|\s]"},index(ri!input,local!length,{}))),
    local!correctvalue:
    if(local!regexMatch,
    replace(ri!input,local!length,1,""),{}),
    if(rule!APN_isEmpty(local!correctvalue),ri!input,
    if(regexmatch({"[$|\s]"},index(local!correctvalue,len(local!correctvalue),{})), 
    rule!rule1(input:local!correctvalue),
    local!correctvalue,
    )))

    SaveInto in the interface:

    saveInto: {
    a!save(local!input,save!value),
    a!save(
    ri!input,
    rule!rule1(input:save!value))}

    to remove empty space in the beginning and at end, in save into call these rules one after the other and then save value

    Hope this helps

Children
No Data