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