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
  • Hi you can convert everything to unicode and use the indices of the first non newline and non spaces to select the text between spaces and newlines by making the use of mid() in this manner:

    load(
    local!unicode: code(ri!input),
    local!indices: enumerate(length(local!unicode))+1,
    local!newlineAndSpaceIndices: append(wherecontains(10, local!unicode), wherecontains(32, local!unicode)),
    local!textIndices: difference(local!indices, local!newlineAndSpaceIndices),
    local!finalText: mid(
    ri!input,
    index(local!textIndices, 1, {}),
    index(local!textIndices, length(local!textIndices), {}) - index(local!textIndices, 1, {}) + 1
    ),
    local!finalText
    )

Reply
  • Hi you can convert everything to unicode and use the indices of the first non newline and non spaces to select the text between spaces and newlines by making the use of mid() in this manner:

    load(
    local!unicode: code(ri!input),
    local!indices: enumerate(length(local!unicode))+1,
    local!newlineAndSpaceIndices: append(wherecontains(10, local!unicode), wherecontains(32, local!unicode)),
    local!textIndices: difference(local!indices, local!newlineAndSpaceIndices),
    local!finalText: mid(
    ri!input,
    index(local!textIndices, 1, {}),
    index(local!textIndices, length(local!textIndices), {}) - index(local!textIndices, 1, {}) + 1
    ),
    local!finalText
    )

Children
No Data