OriginalPostID-174728
Discussion posts and replies are publicly visible
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)
I would start by substituting all "new line" characters with a space; and then use trim() to remove all unnecessary spaces. So:
fn!trim( fn!substitute( ri!myString, char( 10 ), " " ) )
I just noticed the previous replies that reference use of char(13) alongside char(10)...so the principle remains the same, but you'd iterate over the string to substitute both with a space and then tidy it all up with trim():
fn!trim( fn!reduce( fn!substitute, ri!myString, {char(10),char(13)}, " " ) )
Obviously you can extend the list of characters to be excluded as needed..
It's hard to know exaclty what the original poster's use case was from over 4 years ago, but it seems to me that they didn't want to remove all newlines, just extraneous ones (seemingly only at the beginning or end of a string). I'm sure there's now a more graceful coding solution than the original one I posted so long ago, though it's always fun to see my name pop up in a newly-revived thread.